Each value in Minilang has a type which can be determined at runtime. The types of values are used for deciding how operations and methods behave on those values. The type of a value can be obtained using type(Value). Types are usually displayed as <<NAME>>.

3print(type("Hello world"))

Types are values themselves, and can be stored in variables or passed to functions. The type of a type is type.


Types are Functions

This reveals an important feature of Minilang; types can be used as functions. Calling a type as a function is the Minilang way of constructing values of a given type.

1let S := string(1234)
2print('{S} -> {type(S)}\n')
1234 -> <<string>>

Type Inheritance

Each type in Minilang can optionally have parent types. Values of a type inherit behaviour from its parent types, unless that behaviour is overridden in the child type. The set of all types in Minilang forms a tree under inheritance. A subset of that tree is shown in the hierarchy.

The parents of a type can be obtained using Type:parents. The result is returned as a list in no particular order.

[<<number>>, <<integer>>, <<real>>, <<function>>, <<complex>>]

Types have Exports

Types in Minilang can also have named exports, accessible as Type::Name. This is used to collect related values by type, and allows types to be used as modules (when Minilang is built with module support).


Generic Types

Minilang can be built with support for generic types. These are types that are parameterised by other types, along with rules for determining whether one generic type is a parent type of another.