3 ms·
> missing features (like unions) when working with other languages. Which languages are missing unions? Off the top of my head, they exist in C/C++ and mypy py
by MiroF 6y ago
> missing features (like unions) when working with other languages.
Which languages are missing unions? Off the top of my head, they exist in C/C++ and mypy python.
- a_humean 6y agoTypescript allows you to have literal type discriminators in their unions, which combined with control flow based type narrowing of unions effectively gives you sum types. That is what he is talking about, because most mainstream langauges don't have sum types and you need to go to strongly typed functional langauges (haskell, scala, etc...) or modern strongly typed langauges such as Rust to get access to such features.
- lolinder 6y agoYes, this. Sum types in most languages are approximated by something like kotlin's sealed classes. Sometimes you don't want to declare a whole new class hierarchy, you just want to say "this function can either return this or this".