Constructor patterns

A constructor pattern has the form C p1 p2 ā€¦ pn where C is the name of a data constructor in scope, and p1 through pn are patterns such that n is the arity of C. Note that n may be zero. This pattern matches if the scrutinee reduces to a fully applied invocation of the data constructor C and the patterns p1 through pn match the arguments to the constructor.

For example, this expression uses Some and Optional.None, the constructors of the Optional type, to return the 3rd element of the list xs if present or 0 if there was no 3rd element.

xs = [0, 2, 3, 4, 5] match List.at 3 xs with Optional.None -> 0 Some x -> x
ā§Ø
4