10.4.6  type variable identifiers

Unlike C or Java, Mythryl has type variables.

Mythryl uses single-character upper-case identifiers to name type variables. Type variables are wildcards which may match any concrete type:

    List(String)        # A list of strings.
    List(X)             # A list of values of any (single) type.

Type variables are limited in scope to a single type definition, which typically runs a line or less, so usually one to three type variables suffice, which by convention are usually X, Y, Z:

    List(X)                             # A list of values of any (single) type.

    Tree(X,Y)                           # A tree of two unspecified types, one for keys, one for values.
        = PAIR (X,Y)                    # In practice the key type must usually be specified, to allow comparison.
        | LEAF

    Avatar(X,Y,Z)                       # An record of three unspecified types.
          { id:          X,
            description: Y,
            icon:        Z

Any single upper-case letter will be taken for a type variable. In addition, any single upper-case letter followed by an underbar and a lower-case variable is a legal type variable name:

    A B C ... Z

Finally, Mythryl distinguishes between “equality types”, whose values may be compared for equality, and other types, whose values may not.

If a type variable must represent an equality type, that constraint is indicated by adding a leading underbar to its name:

    _X               # equality type variable.

This is much less common in practice than the use of vanilla type variables.

Comments and suggestions to: