Constructed Types¶
This section introduces constructed types which are data types where each datum is constructed from a smaller data items.
Pairs¶
A pair datum (pair) is a combination of two data items.
Type. A pair has a type constructed by fn:Pair(\(S\), \(T\))
where \(S\) and \(T\) are type expressions for the types of the
left and right components of the pair.
Syntax.
If \(e_1\) and \(e_2\) are data items, then
a pair of these is constructed by fn:pair(\(e_1, e_2\)).
Examples.
fn:pair("web", 2.0)
fn:pair("hello", fn:pair("world", "!"))
Tuples¶
A tuple datum (tuple) is a combination of \(n\) data items where \(n >= 3\)
Type. A tuple has type fn:Tuple(\(T_1\),..., \(T_n\))
where \(T_1\)…\(T_n\) are types and \(n >= 3\).
Syntax.
Let \(e_1\) … \(e_n\) be \(n\) data components where \(n >= 3\),
then a tuple of these components is written fn:tuple(\(e_1,...,e_n\)).
Examples.
fn:tuple("hello", "world", "!")
fn:tuple(1, 2, "three", "4")
Lists¶
A list datum (list) is a (possibly empty) sequence of data items.
Type. A list has type fn:List(\(T\)) where
\(T\) is a types.
Syntax.
If \(e_1\) and \(e_n\) is syntax for elements,
the list of these elements is written [\(e_1,...,e_n\)].
The empty list is written [].
A trailing comma is permitted.
Examples
[] # empty list
[,] # also empty list
[0] # list containing single element 0
[/a, /b, /c]
[/a, /b, /c,]
Maps¶
A map datum (map) is a mapping from data items to data items.
Type. A map has type fn:Map(\(S\): \(T\)) where
\(S\) and \(T\) are types.
Syntax.
A map is written […,\(k_i\): \(e_i\),…]
where
\(k_1\) … \(k_n\) are the keys and
\(e_1\) … \(e_n\) are the values.
A trailing comma is permitted.
There is no syntax for empty maps, but an empty map can
be constructed with fn:map(). This syntax is described in a later section.
Examples
[/a: /foo, /b: /bar]
[0: "zero", 1: "one",]
[/a: 1,]
Structs¶
A structure datum (struct) is a record with fields where each field has a designated type.
Type. A struct has type fn:Struct({\(name_i\): \(T_i\)}).
Syntax.
A struct is written {…,\(name_i\): \(e_i\),…}
where \(e_1\) and \(e_n\) are the values.
A trailing comma is permitted.
An empty struct is written {}.
Examples
{}
{,}
{/a: /foo, /b: [/bar, /baz]}