使用模式匹配的因子函式

let rec factorial n = match n with
| `0` | 1 -> 1
| n -> n * (factorial (n - 1))

此函式匹配值 0 和 1,並將它們對映到遞迴定義的基本情況。然後所有其他數字對映到此函式的遞迴呼叫。