Types
Last updated
Was this helpful?
Last updated
Was this helpful?
The following covers the definition of type and their composition and type expressions.
There are three different kinds of type definitions in TreeLDR:
The empty type is defined by simply declaring the name of the type directly followed by a semicolon.
A normal type also declares properties that can be applied to the instances of this type. Properties are listed inside the definition between braces:
The type of each property is specified after a colon :
using a . If a property listed in the definition is declared outside the type definition, it is not required to specify the type of the property again.
Lastly, it is possible to define type aliases. Such a type is defined using a type expression.
A type expression is a composition of existing types by union, intersection and restriction.
The union between two or more types is expressed using the |
operator.
An instance of this type is also an instance of at least one of the listed sub-types.
The intersection between two or more types is expressed using the &
operator.
An instance of this type is also an instance of all the listed sub-types.
Range restrictions are used to select a subset of a type by restricting the range of one of its properties. There are two kinds of range restrictions: universal and existential.
A universal range restriction is built using the all
keyword:
This denotes the type of all values such that all objects of someProperty
are instances of RestrictedType
.
Similarly, the existential range restriction is built using the any
keyword:
This denotes the type of all values such that at least one object of someProperty
is an instance of RestrictedType
.
Range restrictions are usually part of an intersection: