Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match within a match?

Tags:

f#

Is there a way to do a match within a match in F#? I've noticed that you can do one tailed on another like so...

match L.Head with
| null -> []
| _ -> match N with
| 1 -> [L.Head]
| _ -> []

But is there a way to do it so that a match, ending with a _ can be placed in the MIDDLE of another match? This seems to give a bug... is there a better way to do this, should you need it for your logic? EX:

match A with
| 0 -> match B with
       | 1 -> 1
       | _ -> 0
| _ -> 2
like image 573
SwiftCore Avatar asked Mar 22 '23 12:03

SwiftCore


1 Answers

Why not use match on a tuple -

match (A,B) with
|0,1 -> 1
|0,_ -> 0
|_,  -> 2
like image 117
John Palmer Avatar answered Apr 20 '23 15:04

John Palmer