Tutorial by Examples

Pattern matching can be useful to handle Options: let result = Some("Hello World") match result with | Some(message) -> printfn message | None -> printfn "Not feeling talkative huh?"
let x = true match x with | true -> printfn "x is true" yields a warning C:\Program Files (x86)\Microsoft VS Code\Untitled-1(2,7): warning FS0025: Incomplete pattern matches on this expression. For example, the value 'false' may indicate a case not covered by the pattern(s). ...
Incorrect usage: In the following snippet, the last match will never be used: let x = 4 match x with | 1 -> printfn "x is 1" | _ -> printfn "x is anything that wasn't listed above" | 4 -> printfn "x is 4" prints x is anything that wasn't listed abov...
type Person = { Age : int PassedDriversTest : bool } let someone = { Age = 19; PassedDriversTest = true } match someone.PassedDriversTest with | true when someone.Age >= 16 -> printfn "congrats" | true -> printfn "wait until you are 16" | false -> p...

Page 1 of 1