logoalt Hacker News

Splizardyesterday at 8:01 PM3 repliesview on HN

Tagged unions can be implemented in user code, you dont actually need language support to use them.

https://github.com/splizard/tagged


Replies

mirashiiyesterday at 8:11 PM

This 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.

show 1 reply
shhsshsyesterday at 8:26 PM

That 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.

show 1 reply
kccqzyyesterday at 9:25 PM

The 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.