Enumerated Type
Enumerated Type
For example, the four suits in a deck of playing cards may be four enumerators named
CLUB, DIAMOND, HEART, SPADE, belonging to an enumerated type named suits. If a
variable V is declared having suits as its data type, one can assign any of those four
values to it.
The enumerators are necessarily distinct, even though some languages may allow the
same enumerator to be listed twice in the type's declaration. The enumerators need not be
complete or compatible in any sense. For example, an enumerated type called color may
be defined to consist of the enumerators RED, GREEN, ZEBRA, and MISSING. In some
languages, the declaration of an enumerated type also defines an ordering of its members.
Some enumerator types may be built into the language. The Boolean type, for example is
often a pre-defined enumeration of the values FALSE and TRUE. Many languages allow
the user to define new enumerated types.
Values and variables of an enumerated type are usually implemented as fixed-length bit
strings, often in a format and size compatible with some integer type. Some languages,
especially system programming languages, allow the user to specify the bit combination
to be used for each enumerator. In type theory, enumerated types are often regarded as
tagged unions of unit types. Since such types are of the form 1 + 1 + ... + 1, they may also
be written as natural numbers