Difference between revisions of "Type Variables"

From Mesham
Jump to navigationJump to search
m
Line 20: Line 20:
 
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.
 
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''
  
 
[[Category:Types]]
 
[[Category:Types]]

Revision as of 18:12, 13 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.

Since: Version 0.5