Table of Contents
Pattern matching
Example
let rec fact = function | 0 | 1 -> 1 | n when n < 0 -> invalid_arg "fact: arg must be positive" | n -> n * fact (n - 1) let rec is_sorted = function | [] | [_] -> true | n1::(n2::_ as l) -> n1 <= n2 && is_sorted l let safe_tail (_::l | l) = l
See also
- Why I Love F#: Pattern Matching (Dustin Campbell)