Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Java 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/427


They are literally sum types, with records being the corresponding product types.


You can very easily create an Or<T1, T2> class that supports the relevant features.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: