I like to view types as a set of values (eg. string
is the set of all possible strings, int
is the set of all possible integers).
Looking at it this way, there are two common ways types are composed.
Most types people write are product types. Think of it as the product of two sets. If type a
is the set { 1, 2, 3 }
and b
is the set { x, y, z }
, a * b
is { (1, x), (1, y), (1, z), (2, x), (2, y), (2, z), (3, x), (3, y), (3, z) }
. This set contains every possible combination of values from a
and b
.