[swift-evolution] Proposal: An Either Type in the STL

plx plxswift at icloud.com
Thu Dec 10 14:24:06 CST 2015

> On Dec 10, 2015, at 12:38 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>> On Dec 10, 2015, at 10:34 AM, Matthew Johnson <matthew at anandabits.com> wrote:
>>> As an alternative to a semantically-neutral Either type, it might be worth considering the possibility of anonymous structural sum types (similar to how tuples are the structural analog of structs).
>> John mentioned that these are a massive complication for type systems when I proposed them as a possible way to implement throwing multiple error types.  Do you agree with that?
> There are definitely problems if you expect them to behave like unions (so that the type `T + T` == `T`) or be unordered (so that `T + U` == `U + T`), which would be intuitively expected.

FWIW I like the idea of e.g. "structural sum types” in the language, but if e.g. Swift 3 allows this kind of thing:

extension Foo: Baz where Foo.Bar: Baz {

…it is then possible to write sufficiently-useful, adequately-general Sum2, Sum3, etc., types without further language-level support (yes it’s tedious but it’s also a one-off cost).

Given that, language-level support would then seem justified only if there's a very strong sentiment that such types are, say, the right way to design APIs in Swift (which I don’t agree with, and doesn’t seem to to be the community feeling right now, either).

Also FWIW explicit or implicit “proper” unions feel like something I’d be willing to deal with but wouldn’t want to use when at all avoidable.

> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list