Overview
In MUFL, all containers are represented as dictionaries: maps, sets, records, lists and so on.
Map
A map of type A as key into type B as value is represented by a functional type expression type_a->>type_b
.
Example:
Map is int->>str = (1->"hello", 2->"world").
Set
A set of type A is represented by type expression A(,)
or, equivalently, as A->>true+
to indicate that a set is just a map of type A into boolean.
Example:
Set is int(,) = (1,2,5,7).
Array
Arrays are represented as integer-subscripted dictionaries. A shortcut to represent an array is provided with type expression A[]
, which is synonymous to int->>A
. Example:
Array is int[] = [1,2,3,5].
Record
Records are dictionaries with a predefined set of string-typed keys. Example of a record declaration:
Person is ($first_name->str, $last_name->str) = ($first_name->"Alex", $last_name->"Doe" ).
Records are considered compatible when the record being assigned has at least all the fields required by the record assigned to. Extra fields in a record being assigned do not break type compatibility.
Tuple
Tuples are arrays with a set of elements of pre-defined quantity and types. A tuple of type A and type B is represented by type expression [A,B]
.
Example:
Coordinate is [int, int] = [1,50].