案例从上到下进行评估,并使用第一个匹配
使用不正确:
在以下代码段中,永远不会使用最后一个匹配:
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"
版画
x 是上面没有列出的任何内容
正确用法:
在这里,x = 1
和 x = 4
都将触及他们的特定情况,而其他一切都将落到默认情况 _
:
let x = 4
match x with
| 1 -> printfn "x is 1"
| 4 -> printfn "x is 4"
| _ -> printfn "x is anything that wasn't listed above"
版画
x 是 4