<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">One major thing to keep in mind is how exactly will it behave in generic contexts.<div class="">As a similar example, if you can do this:</div><div class=""><br class=""></div><div class="">func foo&lt;A, B&gt;(pass parameter: A, to closure: (A) -&gt; B) -&gt; B {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>closure(parameter)</div><div class="">}</div><div class=""><br class=""></div><div class="">func bar(one: Int, two: Double, three: String) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print(“\(one) \(two) \(three)")</div><div class="">}</div><div class=""><br class=""></div><div class="">foo(pass: (1, 2.0, “3”), to: bar)</div><div class=""><br class=""></div><div class="">This used to work without generics, but If I’m not mistaken, a proposal was accepted to disallow passing tuples and the only argument of a multi-argument function, leaving this use case kinda magical.</div><div class="">This is an enormously useful feature for generic programming (especially with the lack of variadic generic types), because this allows us to define higher-order functions that operate on any type of function, regardless of their arity.</div><div class=""><br class=""></div><div class="">However we resolve the error issue, it has to behave in a similar way, so that throwing and non-throwing functions can be dealt with in a uniform way in a generic context without loss of information or security guarantees.</div><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 2, 2017, at 12:48 AM, Rod Brown &lt;<a href="mailto:rodney.brown6@icloud.com" class="">rodney.brown6@icloud.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2 May 2017, at 2:34 am, John McCall &lt;<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On May 1, 2017, at 9:01 AM, Rod Brown via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div dir="auto" class=""><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">I agree that the key problem with the current architecture that you're alluding to is it can't be easily</span><span class="" style="background-color: rgba(255, 255, 255, 0);">&nbsp;</span><i class="" style="background-color: rgba(255, 255, 255, 0);">stored and transferred.<span class="Apple-converted-space">&nbsp;</span></i><span class="" style="background-color: rgba(255, 255, 255, 0);">Swift errors are great for live action but holding and passing after the throwing event is problematic, and this is an elegant solution.&nbsp;</span><span class="" style="background-color: rgba(255, 255, 255, 0);">The storage issue is when holding it as a property, and&nbsp;</span><span class="" style="background-color: rgba(255, 255, 255, 0);">the transferring issue is when passing it to a closure as a results of an asynchronous operation etc. These are both definitely cases where storage of the type-or-error makes perfect sense.</span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">I think the key problem getting this accepted by the Swift Team will be that it doesn't currently have any specific use in the standard library. As a low level set of types, errors are generated by the lower levels but rarely stored, so the Standard library doesn't need the storage. Generally the only place we have to do that is in end user code. And currently the standard library doesn't have to support asynchronous operations natively, so there's nothing inside the kit that would require it to do completion handlers with errors.</span></div></div></div></blockquote><div class=""><br class=""></div>We've definitely considered including a Result type, but our sense was that in an ideal world almost no code would be using it. &nbsp;It's hard to imagine an ordinary API that ought to be returning a Result rather than throwing, and once you've defined that away, the major remaining use case is just to shift computation around, like with a completion handler. &nbsp;That explicit computation-shifting pattern is something we're hoping to largely define away with something like C#'s async/await, which would leave Result as mostly just an implementation detail of such APIs. &nbsp;We didn't want to spend a great deal of time designing a type that would end up being so marginal, especially if the changing role would lead us into different directions on the design itself. &nbsp;We also didn't want to design a type that would become an obstacle to potential future language changes like, say, typed throws.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">The downside, of course, is that as long as we lack that async/await design, computation-shifting isn't real great.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">John.</div></div></blockquote><div class=""><br class=""></div><div class="">This makes sense and is sensible. I’m curious how such an API would play with the existing NSURLSession completion handlers and the like, but I’m sure the community can design something appropriate.</div><div class=""><br class=""></div><div class="">I think the only remaining case is simply storing a result-or-error for later handling, storage to disk, etc. I agree with your contention that the vast majority of the use case for this type is for computation shifting. I think it would and should be rare that we would want to “store” as a variable the “result-or-error” type. Errors should be handled at runtime in the vast majority of cases, presented to the user or otherwise handled, and then moved on from, with the reason no longer being relevant.</div><div class=""><br class=""></div><div class="">As you say, in the meantime, it does leave computation-shifting a bit ad-hoc and convoluted, but I think the community has standardized on the Result temporary solution.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">This would therefore be an element in the standard library purely so we don't have 50,000 different libraries with 50,000 different result types. I'd love to see this standardised so frameworks were more compatible. I'm just not sure whether the Core Team would see it as pressing to try and officiate a certain type that they themselves don't use.</span></div></div></div></blockquote></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>