t1 * t2 * ... * tNand a product pattern is written as
(p1, p2, ..., pN)In most situations the syntax is quite convenient. However, there are special circumstances under which the syntax for product patterns can be cumbersome.
The problem is best shown through parser combinators. A typical parser combinator library provides a combinator that has a type of the form
'a parser * 'b parser -> ('a * 'b) parserand produces a parser for the concatenation of two parsers. When more than two parsers are concatenated, the result of the resulting parser is a nested structure of pairs
(...((p1, p2), p3)..., pN)which is somewhat cumbersome.
One way around this problem is to use a product datatype
datatype ('a, 'b) product = & of 'a * 'bwith an infix constructor
infix &
The type of the concatenation combinator then becomes
'a parser * 'b parser -> ('a, 'b) product parser
While this doesn't stop the nesting, it makes the pattern significantly easier to write. Instead of
(...((p1, p2), p3)..., pN)the pattern is written as
p1 & p2 & p3 & ... & pNwhich is considerably more concise.
The symbol & is inspired by the Curry-Howard isomorphism: the proof of a conjunction (A & B) is a pair of proofs (a, b).