
Many languages allow users to define new enumerated types. The Boolean type, for example is often a pre-defined enumeration of the values False and True. Some enumerator types may be built into the language. In some languages, the declaration of an enumerated type also intentionally defines an ordering of its members in others, the enumerators are unordered in others still, an implicit ordering arises from the compiler concretely representing enumerators as integers.

For example, an enumerated type called color may be defined to consist of the enumerators Red, Green, Zebra, Missing, and Bacon. The names of enumerators need not be semantically complete or compatible in any sense. If a variable V is declared having suit as its data type, one can assign any of those four values to it.Īlthough the enumerators are usually distinct, some languages may allow the same enumerator to be listed twice in the type's declaration. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but are not specified by the programmer as having any particular concrete representation in the computer's memory compilers and interpreters can represent them arbitrarily.įor example, the four suits in a deck of playing cards may be four enumerators named Club, Diamond, Heart, and Spade, belonging to an enumerated type named suit. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value.

An enumerated type can be seen as a degenerate tagged union of unit type. The enumerator names are usually identifiers that behave as constants in the language. In computer programming, an enumerated type (also called enumeration, enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type.
