5 ms·
What counts as mainstream for you? Java has recently added sealed classes/interfaces which offer the same features as sum types, and I would argue that Java is
by SkiFire13 2y ago
What counts as mainstream for you?
Java has recently added sealed classes/interfaces which offer the same features as sum types, and I would argue that Java is definitely mainstream.
Kotlin has a similar feature. It might be used less than Java, but it's the default language for Android.
Swift has `enum` for sum types and is the default language for iOS and MacOS.
Likewise for Rust, which is gaining traction recently.
Typescript also has union/sum types and is gaining lot of traction.
- zozbot234 2y agoFor that matter, PASCAL has had variant records (i.e. sum types) since the 1970s.
- iso8859-1 2y agoDid it have an ergonomic way to exhaustively match on all the variants? Since the 70s? How does the ABI work? If a library adds a new constructor, but I am still linking against the old version, I imagine that it could be reading the wrong fields, since the constructor it's reading is now at a different index?
- thfuran 2y agoSealed classes still won't let you have e.g. String|Integer, though I'll grant you that java is certainly mainstream.
- kagakuninja 2y agoScala 3 has had union types for 4 years now. Scala can be used to do Haskell style pure FP, but with much better tooling. And it has the power of the JVM, you can fall back to Java libraries if you want.
- SkiFire13 2y agoYou don't really need `String|Integer`, for most usecases an isomorphic type that you can exhaustively pattern match on is more than enough, and sealed classes (along with the support in `switch` expressions) does exactly that.