VARIANT:
Algebraic data types

Next:VARIANT-MEMBER:


Vocabulary
variants

Syntax

VARIANT: class-name singleton singleton tuple: { slot slot slot ... } . . . ;



Word description
Defines class-name as a union of the following singleton-class and tuple-class definitions. Each singleton word is defined as a singleton-class, and each tuple word is defined as a tuple-class with the given set of slot s, using the same syntax for slot specifiers as TUPLE:. Typed tuple slots can recursively reference the variant class-name being defined. For tuple types, a boa constructor word <tuple> is defined as well.

Examples

USING: kernel variants ; IN: scratchpad VARIANT: list nil cons: { { first object } { rest list } } ;



See also
variant-class, match

Definition