first used type Role = President | Secretary | ViceChair; but error:
unexpected token ‘|’, expected one of token or sequence:
}
<typ_args>?
; seplist(<dec_field>,)
or
.
→ <typ_nobin>
and Motoko(M0001) is thrown
Changed to:
type Role = President or Secretary or ViceChair;
President is highlighted with error:
unbound type PresidentMotoko(M0029)
actor {
// three variants with one option
type President = {#president};
type Vice = {#vice};
type Chair = {#chair};
// their union
type Role = President or Vice or Chair;
// an (equivalent) single variant with three options
type Variant = {#president; #vice; #chair};
// adding a variant to a union of named types.
type Mix = President or Vice or Chair or {#secretary};
// tests
public func role(r : Role) : async Text {
debug_show(r);
};
public func variant(r : Variant) : async Text {
debug_show(r);
};
public func mix (r : Mix) : async Text {
debug_show(r);
}
}