Comment on page
📗
Layouts
There are four different kind of layout definitions in TreeLDR:
The empty layout is defined by simply declaring the name of the layout directly followed by a semicolon.
// Empty layout.
layout MyLayout for MyType;
A structure layout is a list of fields each bound to a property of the layout's type.
// Structure layout.
layout MyLayout for MyType {
property1 as fieldName1: Layout1,
// ...
propertyN as fieldNameN: LayoutN
}
The layout of each field is specified after a colon
:
using a layout expression.[To Do]
Lastly, it is possible to define layout aliases. Such a layout is defined using a layout expression.
layout MyLayout = LayoutExpression;
A layout expression is a composition of existing layouts by union, intersection, and restriction.
The union between two or more layouts is expressed using the
|
operator.LayoutA | ... | LayoutN
Under the hood, this implicitly defines an enumeration layout.
The intersection between two or more layouts is expressed using the
&
operator.LayoutA & ... & LayoutN
Range restrictions are used to select a subset of a layout by restricting the range of one of its fields. Just like with types, there are two kinds of range restrictions: universal and existential.
A universal range restriction is built using the
all
keyword:all someProperty as fieldName: RestrictedLayout
This denotes the layout of all instances such that all values of
fieldName
are instances of RestrictedLayout
.Similarly, the existential range restriction is built using the
any
keyword:any someProperty as fieldName: RestrictionLayout
This denotes the layout of all instances such that at least one value of
fieldName
is an instance of RestrictedLayout
.Range restrictions are usually part of an intersection:
Layout & all someProperty as fieldName: RestrictionLayout
Last modified 4mo ago