5 ms·
There is no real reason to have basic enums if you have ADTs , since those can easily provide everything a plain enum gives you. I guess the name was just a hi
by the_duke 4y ago
There is no real reason to have basic enums if you have ADTs , since those can easily provide everything a plain enum gives you.
I guess the name was just a historical artifact.
- SemanticStrengh 4y agono the feature you're looking for is sealed classes, see e.g. Kotlin. Rust enum variants cannot be externally defined classes
- the_duke 4y agoThat's completely orthogonal to ADT vs enum.
- SemanticStrengh 4y agoEnums enable two things: check current type from union of types and exhaustivity check in switch The former is solved by reflection, the latter by sealed classes.
- kaba0 4y agoI agree (that’s what I meant under the more expressive part), though it is a bit more complex with identity in the way. Java’s enums are also the singleton pattern. Java recently got ADTs as well in the form of sealed classes and records, here an enum would look like this: sealed interface Color permits Red, Blue, Green { } record Red() {} record Blue() {} record Green() {} You can now create as many Red instance as you want, they will be “equals” only under equals(), not under ==, while the latter is also true for the enum case.
- brabel 4y agoThe interface implementation types may include enums, though not sure that would help much in your example.