Open LB-- opened 9 years ago
Actually, I think I prefer Rust-style enums (e.g. to implement optional
).
Why not both? Categories and enumerations. Enums could even support the nesting with polymorphic types. Might not even need two separate things at all.
Normal
enum
erations are just as in other languages (e.g. Java). The enumeration is a distinct type with all instances known at compile time. A function which has a parameter of the enum type will accept any of the enum values. However, each value of the enum is actually a singleton of a derived type unique to it. A function can accept a specific enum value type rather than the generic catch-all base.In fact, really an enum is a tree of types where the leafs are singletons and the the rest are abstract.
Example enums with WIP syntax:
Enum instances can also have members specified and can be initialized specially if they have constructors, though I've not yet decided on the syntax for it.