[swift-evolution] Proposal: An Either Type in the STL
Matthew Johnson
matthew at anandabits.com
Thu Dec 10 13:30:47 CST 2015
> 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.
Thanks for explaining the source of complication. These definitely seem like intuitively expected behaviors.
In the context of typed throws we would expect ()->() throws MyError, YourError to be the same as ()->() throws YourError, MyError.
I have an idea that seems obvious enough that there are probably problems with it. Couldn't the type system support a canonical subset of the theoretically possible structural sum types and canonicalize structural sum types immediately when it encounters them? An obvious way to canonicalize would be to sort the types (comparator could be arbitrary as long as it was consistent) and then unique adjacent members. This seems like it would provide the intuitively expected behavior. Is this a viable approach or are there problems with it?
Matthew
More information about the swift-evolution
mailing list