]>
Commit | Line | Data |
---|---|---|
13cf67c4 XL |
1 | # Enumerated types |
2 | ||
3 | An *enumerated type* is a nominal, heterogeneous disjoint union type, denoted | |
4 | by the name of an [`enum` item]. [^enumtype] | |
5 | ||
6 | An [`enum` item] declares both the type and a number of *variants*, each of | |
7 | which is independently named and has the syntax of a struct, tuple struct or | |
8 | unit-like struct. | |
9 | ||
6a06907d | 10 | New instances of an `enum` can be constructed with a [struct expression]. |
13cf67c4 XL |
11 | |
12 | Any `enum` value consumes as much memory as the largest variant for its | |
13 | corresponding `enum` type, as well as the size needed to store a discriminant. | |
14 | ||
15 | Enum types cannot be denoted *structurally* as types, but must be denoted by | |
16 | named reference to an [`enum` item]. | |
17 | ||
5869c6ff | 18 | [^enumtype]: The `enum` type is analogous to a `data` constructor declaration in |
13cf67c4 XL |
19 | ML, or a *pick ADT* in Limbo. |
20 | ||
416331ca | 21 | [`enum` item]: ../items/enumerations.md |
6a06907d | 22 | [struct expression]: ../expressions/struct-expr.md |