2 ms·
Other people have mentioned it in the comments, but they chose the wrong name for these (as did Swift). They're not enums, they're (pick one): - tagged unions
by sirwhinesalot 3y ago
Other people have mentioned it in the comments, but they chose the wrong name for these (as did Swift). They're not enums, they're (pick one):
- tagged unions
- sum types
- algebraic datatypes
- variants
There are some rust packages that transform rust enums into proper enums, the best one being const_table, or my own table_enum. Java got it right except for bundling the data with the Enum object instead of storing it in separate tables.
Having said that, I could not be happier that sum types have entered the mainstream.
- vips7L 3y agoJava has sum types now with sealed classes!
- tialaramex 3y agoI think I have much more problem with the idea that table_enum is "proper enums" than with the choice to name Rust's sum types enum. Because Rust is a low bit-banging language, union needs to exist, which I think rules out calling enum "tagged unions" even if that's one possible way to look at the implementation. In a high level language which lacks union types this wouldn't an issue, but Rust is not that language.