简单的活动模式
活动模式是一种特殊类型的模式匹配,你可以在其中指定数据可能属于的命名类别,然后在 match 语句中使用这些类别。
要定义将数字分类为正数,负数或零的活动模式:
let (|Positive|Negative|Zero|) num = 
    if num > 0 then Positive 
    elif num < 0 then Negative
    else Zero
然后可以在模式匹配表达式中使用它:
let Sign value = 
    match value with
    | Positive -> printf "%d is positive" value
    | Negative -> printf "%d is negative" value
    | Zero -> printf "The value is zero"
Sign -19 // -19 is negative
Sign 2 // 2 is positive
Sign 0 // The value is zero