Tuples
Tuples, unlike lists, can contain elements of different types. The elements of a tuple are enclosed in round parentheses and separated by commas:
The above is an example of a tuple pair that is comprised of two elements, in this case, a string and a boolean. Notice that the tuple type is dependent on its elements β both the number of elements and their individual types. Unlike with lists, where we have one clear type for any single list regardless of its length, tuples must be finite and the type of each element must be known in order for the Haskell type system to able to work properly. The length of a tuple is sometimes referred to as its arity.
Tuples are most commonly used as key-value pairs β a data structure for storing and retrieving data. That is why I said pairs are the most common of tuples β for example, a nameβaddress pair or a dictionary word-definition pair.
Last updated