Difference between revisions of "Type Variables"
(Created page with '== Syntax == typevar name::=type; name::=type; Note how ''::='' is used rather than '':='' ''typevar'' is the type equivalent of ''var'' == Semantics == Type variables allow …') |
|||
Line 9: | Line 9: | ||
== Semantics == | == Semantics == | ||
− | Type variables allow the programmer to assign types and type combinations to variables for use as normal program variables. These exist only in compilation and are not present in the runtime 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 == | == Example == |
Revision as of 16:03, 12 January 2013
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
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.