# Variable Types

Next: Type Variables, Previous: Type Introduction, Index: Index

We have already seen in Variable Declaration how variables are declared to have specific types and how these types are combined. Apart from this, types can also be used on the fly in a number of different situations. Considering the program fragment below:
var i:Int :: allocated[multiple[]];
code....
i:(i :: const[]);
Here the type of variable i is modified after it has been declared (to become a constant value.) This is perfectly allowed, however, after declaration the allocation type information is fixed. Type changes do not need to be perminant, consider the fragment:
var i:Int :: allocated[multiple[]];
code....
i:(i :: channel[1,2]):=82;
i:=12;
In this case, just for the first assignment, the primitive communication type channel (which issues an MPI Send from process 1 to 2) is coherced with variable i. After this assignment the type returns to what it was, and the second assignment results in no communication. There are two additional keywords associated with types:
currenttype [varname];
declaredtype [varname];
The currenttype returns the current type of the variable, whereas declared type returns the declared type of a variable (and can be used to "reset" the variable's type.)
var i:=Int :: allocated[multiple[]];
i:(i :: channel[1,2] :: async[]);
var q:currenttype i;
i:declaredtype i;
In the code above, i is first an integer allocated on all processes. Next the type of i is changed so that it used primitive P2P communication (between 1 and 2) asynchronously. Next the variable q is declared with the current type of i (which is an integer, allocated on all processes, using channel primitive communication, asynchronously.) Lastly, the type of i is changed to that of an Integer allocated on all processes - as it was when it was declared.
Last Modified: August 2008