6 ms·
Tagged unions can be implemented in user code, you dont actually need language support to use them. https://github.com/splizard/tagged https://github.com/spliz
by Splizard 29d ago
Tagged unions can be implemented in user code, you dont actually need language support to use them.
https://github.com/splizard/tagged https://github.com/splizard/tagged
- kccqzy 29d agoThe C++ committee said the same thing, and gave us std::variant. They are painful to work with and do not really deliver most of the benefits people want.
- mirashii 29d agoThis is only a small piece of the story for what people say when they want tagged unions. Without all of the ancillary support in the language, like exhaustive pattern matching, it really doesn't count.
- Splizard 29d agoYou can also add support for exhaustive switches on tags.
- catlifeonmars 28d agoJust as a linter config though?
- Splizard 27d agoNo, by leveraging unkeyed struct initializers as the switch case pattern, which the Go compiler does exhaustiveness checking on.
- shhsshs 29d agoThat is a LOT of code (very ugly code, I would add) that could be replaced by `type Float = float32 | float64` in a language with actual support for union types.
- kccqzy 29d agoTagged unions are not union types. A union type is a supertype for any arbitrary collection of types, but a tagged union aka sum type is a single type with multiple data constructors, and does not require subtyping to be implemented.
- deleted 28d ago[deleted]