next up previous contents index
Next: Types Up: Introduction Previous: Nested Parallelism



As well as sequences, NESL supports the notion of pairs. A pair is a structure with two elements, each of which can be of any type. Pairs are often used to build simple structures or to return multiple values from a function. The binary comma operator is used to create pairs. For example:

The comma operator is right associative (e.g. (2,3,4,5) is equivalent to (2,(3,(4,5)))). All other binary operators in NESL are left associative. The precedence of the comma operator is lower than any other binary operator, so it is usually necessary to put pairs within parentheses.

Pattern matching inside of a let construct can be used to deconstruct structures of pairs. For example:

In this example, a is bound to 8, b is bound to 3, and c is bound to 4.

Nested pairs differ from sequences in several important ways. Most importantly, there is no way to operate over the elements of a nested pair in parallel. A second important difference is that the elements of a pair need not be of the same type, while elements of a sequence must always be of the same type.

Jonathan Hardwick
Tue Nov 28 13:57:00 EST 1995