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

Matthew Johnson matthew at anandabits.com
Wed Dec 9 20:43:11 CST 2015


> We considered it, had some specifics worked out, and then decided to put it on hold.  Part of our reasoning was that it seemed more like an implementation detail of the async / CPS-conversion features we’d like to provide than an independently valuable feature, given that we don’t want to encourage people to write library interfaces using functional-style error handling instead of throws.
> 
> It’s also a feature that’s directly affected by the design of typed throws, which in turn poses some usability challenges for it.  For example, without typed throws you really just want the type to be Result<T>.  With typed throws, can you still write that, or do you have to write Result<T, ErrorType>?  Also, if we want every function result signature to have a corresponding Result<> type, does that permanently prevent us to supporting multiple error types with “typed throws”?  Also, would it be too frustrating to work with typed Result values if we don’t allow implicit covariant conversions along one or both dimensions?

I’m glad to see you holding off until these related design issues are sorted out.  

Can you elaborate on what you mean by a corresponding Result<> type?  I don’t follow the generic argument brackets without any arguments.

When it comes back up and assuming we have typed throws I would like to see support for multiple error types.  I think it could be accomplished via an anonymous compiler generated sum type or something similar to that.  


More information about the swift-evolution mailing list