Metamodel
Goal
Define an architecture to represent a breadth of real-world entities as structured data (models). Specify two operations to act on models: reading and writing. Design a rich system of types, constraints, and invariants, such that any operation always yields a semantically correct model.
We will define the following concepts:
- values
- models
- identifiers
- references
Labels
Going forward, we will need to assign labels to values. To be able to refer to labels in mathematical notation, we define the set
Values
We denote the set of all model values
- Numbers
A number is any of the rational numbers, which we denote
.Examples:
- Bags
A bag is a finite multiset of values. We denote the set of bags over a set
as .Examples:
- Lists
A list is a finite sequence of values. We denote the set of lists over a set
as .Examples:
- Records
Records assign labels to values. They are finite, partial functions from labels to values. We denote the set of records over a set
as .Examples:
Layered Construction
The value kinds above are mutually recursive: bags, lists, and records contain values, which themselves may be bags, lists, or records. To give this a well-defined foundation, we construct
Definition (Value Hierarchy). We define an ascending sequence of sets
Each layer
Definition (Value Domain). The set of all values is the union of all layers:
Theorem (Fixed Point).
Proof sketch.
- (
): Numbers are in . Any bag, list, or record over involves finitely many values, all lying in some layer . Thus it belongs to . - (
): By induction, each , so their union is contained in the right-hand side. ∎
Theorem (Well-Foundedness). Every value
This ensures the axiom of regularity: there are no infinite descending chains of membership.
Models
Model Part
A model part assigns labels to data, thereby describing the data’s meaning. Formally, we define a model part as a function into
Type System
Overview
A type system classifies values into types, enabling static reasoning about program behavior. In our metamodel, types are defined as subsets of the value domain
Type Syntax
We define the set of types
where:
are distinct labels are type variables are types that may reference the bound type variables
Primitive Types
: All rational numbers, : All integers,
Singleton Types
For each value
Parameterized Types
Bag type:
List type:
where
Record type:
Open records support width subtyping: a record with additional keys is a subtype.
Closed record type:
Sequence Types
Cons type:
This constructor requires that
Interval Types
Interval types represent subsets of
with the constraint that inclusive bounds must be finite: if
Notation:
Numeric Types
Multiplication type:
This constructor requires that
Set Operations
Union:
Intersection:
Set difference:
Recursive Types
Single Recursive Types
A recursive type
Semantics: The semantic function maps recursive types to the least fixed point of a recursive equation:
where
Example: A tree type:
The semantic equation is:
The least fixed point is the set of all finite trees with integer values.
Base cases: A recursive type is inhabited if and only if its semantic equation has a non-empty least fixed point. This requires the type to have base cases that allow the recursion to terminate with finite, well-founded values.
Example (inhabited):
Example (uninhabited):
Mutually Recursive Types
Mutually recursive types are defined as a simultaneous fixed point of multiple type equations:
Semantics: The semantic function maps this to the least fixed point of the system of equations:
Example: Doubly-linked list nodes:
This defines two types
Subtyping
Subtyping is derived from set inclusion of the semantic function:
Examples:
because because (width subtyping for open records) because
Type Equivalence
Two types are equivalent if they have the same semantics:
Typing Relation
A value