function定义函数主体时,关键字自动具有模式匹配。在下面观察它:
# let foo = function 0 -> "zero" | 1 -> "one" | 2 -> "couple" | 3 -> "few" | _ -> "many";; val foo : int -> bytes = <fun> # foo 0;; - : bytes = "zero" # foo 3;; - : bytes = "few" # foo 10;; - : bytes = "many" # let bar = function "a" | "i" | "e" | "o" | "u" -> "vowel" | _ -> "consonant";; val bar : bytes -> bytes = <fun> # bar "a";; - : bytes = "vowel" # bar "k";; - : bytes = "consonant"