3 Main Features of Curry

3.9 Tuple

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:

data Pair a b = Pair a b
data Triple a b c = Triple a b c

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.

For example, the information system of a “Big & Tall” shoe store declares a function that defines the largest size and width of each model [Browse Program][Download Program]:

data Width = C | D | E | EE | EEE | EEEE
largest "New Balance 495" = Pair 13 EEE
largest "Adidas Comfort"  = Pair 15 EE
...

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:

largest "New Balance 495" = (13,EEE)
largest "Adidas Comfort"  = (15,EE)
...

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:

largest :: String -> (Int,Width)