APITuple
Tuple
Pairs and triples, and their accessors.
(a, b) and (a, b, c) are surface syntax for Pair and Triple, in
type, expression, and pattern position alike, so a file that only uses
tuple syntax needs no import; naming Tuple, Pair, or Triple does.
Tuples compare component by component, left to right, and display the way
they are written: (1, "one").
Arity stops at three. Past three, a record with named fields reads better than positional ones.
Pair
type Pair a b = Pair a bSource
Two values, written (a, b).
(1, "one") == (1, "one")
(1, "z") < (2, "a")
show (1, 'x') == "(1, 'x')"
Instances:
(Eq a, Eq b) => Eq (a, b)
(Ord a, Ord b) => Ord (a, b)
(Show a, Show b) => Show (a, b)
Triple
type Triple a b c = Triple a b cSource
Three values, written (a, b, c). There are no accessors; match
(a, b, c) to reach its components.
Constructors
Instances:
(Eq a, Eq b, Eq c) => Eq (a, b, c)
(Ord a, Ord b, Ord c) => Ord (a, b, c)
(Show a, Show b, Show c) => Show (a, b, c)
first
first : (a, b) -> aSource
The first component of a pair.
import Tuple
Tuple.first (1, "one") == 1
second
second : (a, b) -> bSource
The second component of a pair.
import Tuple
Tuple.second (1, "one") == "one"
swap
swap : (a, b) -> (b, a)Source
The pair with its components exchanged.
import Tuple
Tuple.swap (1, "one") == ("one", 1)
