Pair
Note: Pair types and values can be expressed using tuple syntax as
(Integer, String)
and(3, "OH NO!")
; this is preferred over direct use of pairs in most cases. See the tuples page for more information.
local attribute symbolDef :: Pair<String Integer>;
symbolDef = pair(fst="a", snd=3);
Pairs are also provided as a standard data structure in core. Pairs are the first data structure that is completely unspecial–that is, it’s an ordinary nonterminal with no special language support.
The pair type is written Pair<a b>
where a
and b
are
types.
Pairs are constructed using the pair
constructor:
annotation fst<a>::a;
annotation snd<a>::a;
nonterminal Pair<a b> with fst<a>, snd<b>;
abstract production pair
top::Pair<a b> ::=
Here fst
and snd
are annotations, meaning they must be supplied as named arguments to the constructor.
Example:
local attribute priorityError :: Pair<Integer String>;
priorityError = pair(fst=3, snd="OH NO!");
The elements are accessed using the fst
and snd
annotations.
Example:
if priorityError.fst > 2
then print("Error: " ++ priorityError.snd, ioin)
else print("No serious errors.", ioin)
Up to date information about this data structure can be found in core/Pair.sv
.