案例從上到下進行評估,並使用第一個匹配

使用不正確:

在以下程式碼段中,永遠不會使用最後一個匹配:

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 = 1x = 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