Variants

In this section, we’ll look at variants, also referred to as enums. Variants allow you to define a type by enumerating its possible variants.

Variants are objects and thus have methods associated with them. Use keywords ::E, ::V to define variants.

    ::E :Day, [
        :Monday: 1,
        :Tuesday, :Wednesday, :Thursday, :Friday, :Saturday,
        :Sunday
    ], {
        # Define methods
        :to_str :  {?. # default use self '.'
            :- Monday: "Monday"
            ...
        }
    }
    \< ( ::a Day, 1 ).to_str
    # Prints "Monday"

Work in progress....