Enumeration maps a list of names to either a string or integer value. Within a module the enumeration has a similar form to other top level blocks. The following code defines an enumeration
enum_name with three values
If no values are given to the names then the first value will be 0. Each subsequent value will be one larger than the previous value. So in this example
identifier_0 is 0,
identifier_1 is 1 and
identifier_2 is 2. The default values can be overridden:
Using the -> operator allows the value to be replaced. In this example,
car is 5,
boat is 6,
plane is 8 and
tank is 9. It is legal to have multiple names mapping to the same value though the names themselves must be unique. Alternatively an enumeration may map to string values. This is done by giving one of the values a mapping to a string. Any unmapped value will take the string representation of its name. Given
car is "car",
boat is "water" and
plane is "plane". Strings and numbers may not be mixed within a single enumeration.
Enumeration values can be used in metadata or in an assignment within a pattern. Metadata has been extended so it now also supports numbers.
The pattern assigns the variable
a the value "water". Enumeration values cannot be used within expressions.