"Oneof"s are created using constructors. Associated with each "oneof" type there is a set of constructors, one for each tag of the type. Here is an example:
ot = oneof[some: int, none: null] % a oneof type
x: ot % a variable to denote objects of this type
x := ot{none: nil} % creating an object with the none tag
if x.is_none( ) then % checking the tag
x := ot{some: 7} % creating an object with the some tag
end
tagcase x % decomposing a oneof using the tagcase statement
when none: ...
when some(y: int): ...
end
Methods for "oneof" type "ot"
is_a ( ) returns (bool)
% (here a is a tag name and T is the corresponding type)
% effects returns true if the tag of self is a else returns false
value_a ( ) returns (T) signals (wrong_tag)
% (here a is a tag name and T is the corresponding type)
% effects if the tag of self is a returns the associated object else signals wrong_tag
equal (x: ot) returns (bool)
where all field types T have equal (T) returns (bool)
% effects returns true if self and x have the same tag and equal values (determined
% by calling the equal method for the value).
similar (x: ot) returns (bool)
where all field types T have similar (T) returns (bool)
% effects returns true if self and x have the same tag and similar values (determined
% by calling the similar method for the value).
copy ( ) returns (ot)
where all field types T have copy ( ) returns (T)
% effects returns a new oneof object with the same tag as self and whose value is a
% copy (obtained by calling the value's copy method) of that of self
unparse ( ) returns (string)
where all field types T have unparse ( ) returns (string)
% effects returns a string representing the tag and value of self. The form of the string
% is oneof{t: v}, where t is a string corresponding to the current tag and v is
% produced by calling the unparse method of the value