-
Notifications
You must be signed in to change notification settings - Fork 1
Type alias
Note: the syntax described on this page is available from GeoDMS version 20.9.0 and later.
A type alias gives a name to a type, so that the same type can be reused wherever a type is expected. It is written with a single equals sign:
A type alias is declared as alias = type;.
This is deliberately distinguished from the item declaration name : type;, which declares an item of that type. The colon form introduces a data item (or unit, container, ...); the equals form introduces only a name for the type itself.
flt = attribute<float64>; // type alias: 'flt' names the type attribute<float64>
x1 : flt (Road); // item declaration: 'x1' IS an attribute<float64> on Road
A plain alias names an attribute or unit type:
flt = attribute<float64>;
dom = unit<uint32>;
Once declared, the alias may be used anywhere the underlying type could be written — as the type of an item, or as a parameter type in a function signature:
x1: flt (Road) := Road/flow * 1.0;
Here x1 is an attribute<float64> on the domain unit Road, exactly as if attribute<float64> had been written in full.
An alias may itself refer to a previously declared alias. More generally, any previously declared item can serve as a type — the alias clones that item's type. This is the "type by example" mechanism:
dom2 = dom; // alias of an alias
D2: dom2 : nrofrows = 2; // D2 is a unit<uint32> with 2 rows
Aliases are resolved by name against the enclosing scope, following the ordinary declared-before-use and parent-chain rules, so an alias declared in a container is visible to the items and functions within it.
The same alias = ... form also names a function signature — the parameter and result types of a function, without a body:
unary_fn = (unit<uint32> D; attribute<float64> v (D)) -> attribute<float64> (D);
A signature alias may be generic, introducing type variables:
nuf = function<V: numerics, D: domains>(attribute<V> (D)) -> attribute<V> (D);
Such an alias is used to type a function-valued parameter. Every function bound to that parameter is checked against the signature at application time:
function ApplyTwiceT(unit<uint32> D; f: unary_fn; attribute<float64> x (D))
-> attribute<float64> (D) := f(D, f(D, x)); // f is checked against unary_fn
Applying a signature alias directly is an error — it has no body. See Function-signature for the full syntax and the checking rules.
Plain-type aliases expand at parse time: the alias is substituted for its underlying type as the configuration is read, so it has no separate runtime representation. Because resolution is lexical, aliases scope to their enclosing container and survive #include boundaries.
20.9.0
GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.