Each-of types; a value of type t
contains values whose types follow each oft1
, t2
, t3
, …, tn
(e.g. tuples, records)
int * bool
contains each of the following:
int
bool
int * bool
contains an int
AND a bool
One-of types; a value of type t
contains values whose types follow one of t1
, t2
, t3
, …, tn
(e.g. enumerations, itemizations)
NONE
SOME e
int option
either contains no data (NONE
) OR some data (SOME int
)Self-reference (self-referential data types e.g. lists, trees)
xs
is one of the following:
NONE
SOME (x :: xs)
xs
is…
int
and an int list
NONE
or SOME (x :: xs)
.xs
references itself in its type comment.<aside> 💽 Records are also called structures (…sound familiar?)
</aside>
Records are a form of compound data that encapsulates multiple pieces of related data.
They are identical to structures and bear some similarities to objects from OOP languages.
Syntax: {f1 = v1, f2 = v2, f3 = v3, ... fn = vn}
, where f1...fn
are field names and v1...vn
are values.
Type-checking rules: {f1 : t1, f2 : t2, f3: t3, ... fn : tn}
, where f1...fn
are field names and t1...tn
are the types of values v1...vn
.