On this page ...
Generic Types: an Example Typer Definition
This example shows how generic types and units of measurement can be defined.
The Example Language
The language is intentionally simple: its units consist of lists of expression – declared type pairs.
Ultimately, we want to compare the declared type with the inferred type of the expression.
Below is an example of a model unit in this language.
UnitA correctExps
12 : NUMBER;
"string" : STRING;
2345: NUMBER;
"this is a large string": STRING;
true : BOOLEAN;
false: BOOLEAN;
Set{ true, true, false } : Set<BOOLEAN>;
Bag { Set { 12, 13, 14 }, Set { 12, 13, 14, 15, 16 } } : Bag<Set<NUMBER>>;
124 Meters : Meters<NUMBER>;
45 kWh : kWh<NUMBER>; Next, we’ll explain the metamodel of this language.