13.1 Tuples
We can combine several values in a comma separated list to form tuple.
1,2.9,"Hello"
The type of this value is:
int * double * string
The {*} symbol here means that the int
, double
, and string
types are joined into a collective type of all three together--order matters!
The type of a tuple is sometimes called the Cartesian Product (after Descartes). You can retrive a value from a tuple with a integral literal: Note the field numbers are zero origin in keeping with C conventions.
val x = 1,2.9,"Hello"; println x.0; // 1 println x.1; // 2.9 println x.2; // "Hello"
1 2.9 Hello
There are no tuples with one component.
13.1.1 Unit
However, there is a tuple with no components with a single unique value:
()
the type of which is called unit
type and can also
be designated by 1
.