<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Note: I'm going to talk about the Result&lt;T,E&gt; type here, which is somewhat tangential to this thread as this thread is not in fact proposing Result&lt;T,E&gt;, and I'm not expecting to have a real discussion about how Result&lt;T,E&gt; would be designed at this point. I'm just writing my thoughts down as a reply to Chris Lattner. This can be explored more fully at such time as we do try to develop a concrete proposal for a Result&lt;T,E&gt; type.<br></div>
<div>&nbsp;</div>
<div>On Tue, Jan 26, 2016, at 10:31 PM, Chris Lattner wrote:<br></div>
<blockquote type="cite"><div><blockquote type="cite">You know my counterarguments about the name. &nbsp;But at this point as long as I get an unconstrained Result in two type parameters I'm fine because that's&nbsp;the structure we are advocating for in the proposal.&nbsp;&nbsp;<br></blockquote><div>&nbsp;</div>
<div>To set expectations, I’d expect the Result type to be specifically designed to serve the problem domain of capturing a return value. &nbsp;Even assuming we get “typed throws”, I’d expect the error argument to have an ErrorType constraint on it. &nbsp;Further, if we expand the function result type model, we’d expect Result to track that. &nbsp;I would also expect the Result type to have methods on it specific to its domain.<br></div>
<div>&nbsp;</div>
<div>This means that it will not be unconstrained, and not a generic type like the Either you are proposing.<br></div>
</div>
</blockquote><div>&nbsp;</div>
<div>I'd prefer to have an unconstrained Result&lt;T,E&gt; that has extensions for E: ErrorType. I don't think there's any particular value in defining the type itself as Result&lt;T, E: ErrorType&gt; because most of the methods won't care about the ErrorType bounds, and the methods that we'd want to have that do care about it aren't crucial to the basic operation of the type. Having it unconstrained will also allow people to use Result&lt;T,ErrorType&gt; (given that existential protocol values don't conform to the protocol, although I haven't been following everything so maybe there's already plans to change that?).<br></div>
<div>&nbsp;</div>
<div>However, doing this properly with an unconstrained Result&lt;T,E&gt; does run into the limitation where you can't say `extension Result where E == ErrorType` to add methods for when E is the ErrorType existential (though if we do change it so the ErrorType existential conforms to ErrorType then `extension Result where E: ErrorType` will work just fine). We'd probably also want to add support for generic parameters on typealiases, so you can say `typealias FooResult&lt;T&gt; = Result&lt;T, FooError&gt;`.<br></div>
<div>&nbsp;</div>
<div>There's also some questions about how this would interact with "typed throws" (assuming we get typed throws), e.g. if a function can return one of 3 different error types, how would you represent this with a Result&lt;T,E&gt; (short of manually defining a new enum with a variant for each case), and so if we are going to get "typed throws" then it makes some sense to wait until we have some idea of how that's going to work before designing a Result type that expects to interact with errors.<br></div>
<div>&nbsp;</div>
<div>All that said, I don't feel all that strongly about this. I'd guess that most uses of Result would have either the ErrorType existential or some type that conforms to ErrorType as the E parameter even if Result is unconstrained, so constraining it as Result&lt;T,E: ErrorType&gt; isn't too limiting, but it does just seem like an unnecessary restriction as far as defining the Result type itself goes.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard<br></div>
</body>
</html>