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

We added sum types and exhaustive pattern matching in Dart 3.0.

Union types (what the proposal here calls "ad hoc unions") are a separate, much harder feature whose value proposition is less clear. The cost of adding a new kind to the type system is quite large because it impacts method resolution, overriding, type inference, subtyping, least upper bound, generics, type promotion, etc.

It can be worth it (for example, we added tuple/record types in Dart 3.0), but the value proposition must be correspondingly high to justify it. It's not clear that union types meet that bar yet. In many if not most of the places where users are asking for it, it often seems like what they really want is overloading or some other feature.



Thanks, I appreciate the explanation a lot! I find losing the type hints because I am forced to type something as "dynamic" is a bummer, I hope exhaustive pattern matching solves cases like these: https://github.com/pocketbase/dart-sdk/blob/master/lib/src/a...

Related issue: https://github.com/dart-lang/language/issues/83




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

Search: