5 ms·
I do know those languages, but this is more the ADT way from ML. The example you linked did not really make it clear from my point of view because one of the p
by erk__ 4y ago
I do know those languages, but this is more the ADT way from ML.
The example you linked did not really make it clear from my point of view because one of the points is that it will collapse if there are multiples of a specific type. But your way seems to make it possible.
- ddevault 4y agoRight - but defining a type alias makes a new type, which does not collapse.
- nyanpasu64 4y agoTagged unions of free-floating types (polymorphic variants, C++ std::variant) and enum holding cases namespaced within themselves (Rust/Haskell) are two alternative designs. I personally prefer having both in a language. But if only one is available in a language, I prefer free-floating types, since it's more flexible and allows using the same type in multiple tagged unions, and you can somewhat emulate enums using tagged unions and namespaces (like I've done in C++ at https://gitlab.com/exotracker/exotracker-cpp/-/blob/eb8458b2638da7d354a4de41a805113330d84aa3/src/edit/edit_pattern.h#L15-33= https://gitlab.com/exotracker/exotracker-cpp/-/blob/eb8458b2...). If you take that approach, to prevent collapsing in the generic case when two type parameters are the same, you'd have to define newtypes for each type stored in a union.