Guards

Cases of a pattern matching can include guard expressions, which are arbitrary boolean expressions that must evaluate to true for the match case to be selected. Guards occur just before the -> token and are introduced by the when keyword:

match expr with
      pattern1 [when cond1] -> expr1
    | ...
    | patternN [when condN] -> exprN
(Same syntax for the fun, function, and try ... with constructs.) During matching, if the value of expr matches some pattern patterni which has a guard condi, then the expression condi is evaluated (in an environment enriched by the bindings performed during matching). If condi evaluates to true, then expri is evaluated and its value returned as the result of the matching, as usual. But if condi evaluates to false, the matching is resumed against the patterns following patterni.