
The table below shows the relative precedences and associativity of operators and nonclosed pattern constructions. The constructions with higher precedences come first.
Operator  Associativity 
Constructor application  – 
::  right 
,  – 
  left 
as  – 
Patterns are templates that allow selecting data structures of a given shape, and binding identifiers to components of the data structure. This selection operation is called pattern matching; its outcome is either “this value does not match this pattern”, or “this value matches this pattern, resulting in the following bindings of names to values”.
A pattern that consists in a value name matches any value, binding the name to the value. The pattern _ also matches any value, but does not bind any name.
Patterns are linear: a variable cannot appear several times in a given pattern. In particular, there is no way to test for equality between two parts of a data structure using only a pattern (but when guards can be used for this purpose).
A pattern consisting in a constant matches the values that are equal to this constant.
The pattern pattern_{1} as valuename matches the same values as pattern_{1}. If the matching against pattern_{1} is successful, the name name is bound to the matched value, in addition to the bindings performed by the matching against pattern_{1}.
The pattern ( pattern_{1} ) matches the same values as pattern_{1}. A type constraint can appear in a parenthesized pattern, as in ( pattern_{1} : typexpr ). This constraint forces the type of pattern_{1} to be compatible with typexpr.
The pattern pattern_{1}  pattern_{2} represents the logical “or” of the two patterns pattern_{1} and pattern_{2}. A value matches pattern_{1}  pattern_{2} either if it matches pattern_{1} or if it matches pattern_{2}. The two subpatterns pattern_{1} and pattern_{2} must bind exactly the same identifiers to values having the same types. Matching is performed from left to right. More precisely, in case some value v matches pattern_{1}  pattern_{2}, the bindings performed are those of pattern_{1} when v matches pattern_{1}. Otherwise, value v matches pattern_{2} whose bindings are performed.
The pattern constr pattern_{1} matches all variants whose constructor is equal to constr, and whose argument matches pattern_{1}.
The pattern pattern_{1} :: pattern_{2} matches nonempty lists whose heads match pattern_{1}, and whose tails match pattern_{2}.
The pattern [ pattern_{1} ; … ; pattern_{n} ] matches lists of length n whose elements match pattern_{1} …pattern_{n}, respectively. This pattern behaves like pattern_{1} :: … :: pattern_{n} :: [].
The pattern `tagname pattern_{1} matches all polymorphic variants whose tag is equal to tagname, and whose argument matches pattern_{1}.
If the type [('a,'b,...)] typeconstr = [`tag_{1} typexpr_{1}  …  `tag_{n} typexpr_{n}] is defined, then the pattern #typeconstr is a shorthand for the orpattern (`tag_{1}(_ : typexpr_{1})  …  `tag_{n}(_ : typexpr_{n})). It matches all values of type #typeconstr.
The pattern pattern_{1} , … , pattern_{n} matches ntuples whose components match the patterns pattern_{1} through pattern_{n}. That is, the pattern matches the tuple values (v_{1}, …, v_{n}) such that pattern_{i} matches v_{i} for i = 1,… , n.
The pattern { field_{1} = pattern_{1} ; … ; field_{n} = pattern_{n} } matches records that define at least the fields field_{1} through field_{n}, and such that the value associated to field_{i} matches the pattern pattern_{i}, for i = 1,… , n. The record value can define more fields than field_{1} …field_{n}; the values associated to these extra fields are not taken into account for matching.
The pattern [ pattern_{1} ; … ; pattern_{n} ] matches arrays of length n such that the ith array element matches the pattern pattern_{i}, for i = 1,… , n.