Type Variables

From Mesham
Revision as of 15:44, 15 April 2019 by Polas (talk | contribs) (4 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Syntax

typevar name::=type; name::=type;

Note how ::= is used rather than := typevar is the type equivalent of var

Semantics

Type variables allow the programmer to assign types and type combinations to variables for use as normal program variables. These exist only statically (in compilation) and are not present in the runtime semantics.

Example

function void main() {
   typevar m::=Int :: allocated[multiple[]];
   var f:m;
   typevar q::=declaredtype f;
   q::=m;
};

In the above code example, the type variable m has the type value Int :: allocated[multiple[]] assigned to it. On line 2, a new (program) variable is created using this new type variable. In line 3, the type variable q is declared and has the value of the declared type of program variable f. Lastly in line 4, type variable q changes its value to become that of type variable m. Although type variables can be thought of as the programmer creating new types, they can also be used like program variables in cases such as equality tests and assignment.

Since: Version 0.5