A tuple is a product of values.
A tuple is written with parentheses.
For example, here is a 2-tuple (a pair) of an
Int32 and a
The type of the tuple is
We can destructure a tuple using pattern matching. For example:
let t = ("Lucky", "Luke", 42, true); // 4-tuple let (fstName, lstName, age, male) = t; lstName
evaluates to the string
The Flix prelude defines the
let t = (1, 2); let x = fst(t); // x = 1 let y = snd(t) // y = 2
which are useful when working with 2-tuples (i.e. pairs). For example:
let l = (1, 1) :: (2, 2) :: Nil; // has type List[(Int32, Int32)] List.map(fst, l) // has type List[Int32]
which evaluates to a list that contains all the
first components of the list