Aconstructor patternhas the form `C p1 p2 … pn'' where
Cis the name of a data constructor in scope, and
pnare patterns such that
nmay be zero. This pattern matches if the scrutinee reduces to a fully applied invocation of the data constructor
Cand the patterns
pnmatch the arguments to the constructor.
For example, this expression uses
None,the constructors of the
Optionaltype, to return the 3rd element of the list
xsif present or
0if there was no 3rd element.
The arity of a function or data constructor describes the number of arguments that it takes.
For example, the function
addThree : Nat -> Nat -> Nat -> Natis a function of arity 3.
Some arities are common enough they get special terms:
- A "nullary" function has 0 arguments
- A "unary" function has 1 arguments
- A "binary" function has 2 arguments
- A "ternary" function has 3 arguments