![]() |
|
Navigation |
Synopsis Declare an alias for a type.
Syntax
alias Name = Type;
Description Everything can be expressed using the elementary types and values that are provided by Rascal.
However, for the purpose of documentation and readability it is sometimes better to use a descriptive name as type indication, rather than an elementary type. The use of aliases is a good way to document your intentions.
An alias declaration states that Name can be used everywhere instead of the already defined type Type .
Both types are thus structurally equivalent.
Examples Introduce two aliases
ModuleId and Frequency for the type str.
rascal>alias ModuleId = str; ok rascal>alias Frequency = int; okAnother example is an alias definition for a graph containing integer nodes: rascal>alias IntGraph = rel[int,int];
ok
Note that the Rascal Standard Library provides a graph data type that is defined as follows:
rascal>alias Graph[&T] = rel[&T, &T];
ok
In other words the standard graph datatype can be parameterized with any element type.
See TypeParameters for other examples parameterized alias declarations. ![]() |