3 ms·
Static types are great, but they can be quite painful in languages like Java that don't support Sum Types/Tagged Unions. I just want to represent "OR" goddammit
by nicoburns 4y ago
Static types are great, but they can be quite painful in languages like Java that don't support Sum Types/Tagged Unions. I just want to represent "OR" goddammit.
It should also be noted that statically typed doesn't necessarily imply verbose. Many statically typed languages support type inference which more or less gives you the best of both worlds.
- 5e92cb50239222b 4y agoJava supports sealed classes (which is close enough to sum types at least for the stuff I work on), and pattern matching over them is in preview. https://openjdk.org/jeps/409 https://openjdk.org/jeps/409 https://openjdk.org/jeps/427 https://openjdk.org/jeps/427
- kaba0 4y agoThey are literally sum types, with records being the corresponding product types.
- UncleMeat 4y agoYou can very easily create an Or<T1, T2> class that supports the relevant features.