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 …') |
m (4 revisions imported) |
||
(3 intermediate revisions by the same user not shown) | |||
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 == | ||
− | typevar m::=Int :: allocated[multiple[]]; | + | 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. | 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]] |
Latest revision as of 15:44, 15 April 2019
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