The word “tuple” is a generic name for a family of related types. A tuple in a program is similar to a tuple in mathematics, i.e., a fixed length sequence of values of possibly different types. Examples of tuples are pairs and triples. They could be defined by the programmer as follows:
These types are polymorphic. Observe the two occurrences of the identifiers “Pair” and “Triple” in the above declarations. The occurrence to the left names a type constructor, whereas the occurrence to the right names a data constructor. These symbols are overloaded. However, this kind of overloading causes no problems since type expressions are clearly separated from value expressions. The type variables “a”, “b” can be bound to different types.
The language predefines tuples and denotes them with a special notation similar to the standard mathematical notation. Using predefined tuples, the above function is coded as:
Tuples are denoted by a fixed-length sequence of comma-separated values between parentheses. There is no explicit data constructor identifier. The type of a tuple is represented as a tuple as well, e.g., the type of “largest” can be defined as: