Guard patterns

A guard pattern has the form p | g where p is a pattern and g is a Boolean expression that may reference any variables bound in p. The pattern matches if p matches and g evaluates to true.

For example, the following expression evaluates to 6:

match 1 + 2 with
  x
    | x == 4     -> 0
    | x + 1 == 4 -> 6
  _              -> 42