Have a problem with use of '|' operator in creating type

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)

I want only one option to be given of the three

Here’s some examples. Hope that helps:

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);
  }

}

Internet Computer Loading

3 Likes