Tuples, records and tagged values are compound values obtained by combining values of other types. Tuples are used in expressing “functions of several variables” where the argument is a tuple, and in expressing functions where the result is a tuple. The components in a record are identified by special identifiers called labels. Tagged values are used when we group together values of different kinds to form a single set of values. Tuples, records and tagged values are treated as “first-class citizens” in F#: They can enter into expressions and the value of an expression can be a tuple, a record or a tagged value. Functions on tuples, records or tagged values can be defined by use of patterns.
Tuples
An ordered collection of n values (v1, v2,…,vn), where n > 1, is called an n-tuple. Examples of n-tuples are:
(10, true);;
val it : int * bool = (10, true)
((“abc”,1),–3);;
val it : (string * int) * int = ((“abc”, 1), –3)
A 2-tuple like (10,true) is also called a pair. The last example shows that a pair, for example, ((“abc”,1),–3), can have a component that is again a pair (“abc”,1). In general, tuples can have arbitrary values as components. A 3-tuple is called a triple and a 4-tupleis called a quadruple. An expression like (true) is not a tuple but just the expression true enclosed in brackets, so there is no concept of 1-tuple. The symbol () denotes the only value of type unit (cf. Page 23).