Skip to content
A scene from Ireland

Tuples

Tuples are a useful construct in a programming language, as long as we know what they are...

A tuple is a fixed collection of other objects. It is different from a list in that it is not extensible: once it has been created, it stays that size. Also, unlike lists, the elements can be of different types. Thus it is more substantially like a Pascal record of C struct.

The value of a tuple over a struct is anonymity. It is sometimes useful to have a struct that is not explicitly typed, but still have enough type information to be passed around safely. Effectively there are standard labels "first" and "second" etc, and type matching is based on substructure matching.

In some languages, such as python, the arguments to a function can be passed positionally or by name. This could be seen as the arguments being a tuple which is addressed either by standard labels (first, second, etc) or by pre-defined names. However argument lists can usefully be of varying length, which is at odds with a tuples pre-defined structure.

UNFINISHED