<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 27, 2016, at 06:38, Anton Zhilin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div dir="ltr" class=""><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important" class="">On syntax, I feel like this is the obvious one:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class=""><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important" class="">func convert(_: String) -&gt; Int throws IntegerConversionError
</code></pre></div></div></div></blockquote><div>I agree this is the best syntax, though I might add a comma in there for even more readability:</div><div><br class=""></div><div>func convert(_:String) -&gt; Int<b class="">,</b> throws IntegerConversionError {</div><div>&nbsp; &nbsp;...</div><div>}</div><div><br class=""></div><div><br class=""></div><div>I wonder if this might be problematic in the presence of trailing where clauses though, as in this contrived example:</div><div><br class=""></div><div>func doSomething&lt;S:Sequence&gt;(seq:S) -&gt; Int where S.Iterator == T, S.Iterator: Hashable, throws SomeKindOfError {</div><div>&nbsp; &nbsp;...</div><div>}</div><div><br class=""></div><div>It seems like it should be alright, but perhaps I’m missing something.</div><div><br class=""></div><div>-Matt</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important" class="">Basically, we say that the function can either return an <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Int</code>, or throw an <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">IntegerConversionError</code>. (Side note: yes, not <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">NumericConversionError</code>, if we want the API to both provide most detailed information when we need it, and express the range of possible errors for a particular function through the type system. However, one can also create hierarchies of error protocols to aid in abstraction—both abstraction and preciseness are important.)</p><p style="margin:0px 0px 1.2em!important" class="">But can we make a step even further? One can say that the function returns “either Int or an error”. Rust users blame Swift for creating syntax sugar for everything—maybe we can live without it this time? Look at it this way: we already have a deep support for <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Optional&lt;T&gt;</code> in the language. It’s so seamless, many people don’t even <em class="">realize</em> they work with <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Optional&lt;T&gt;</code>. Can we make working with a standard enum <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Result&lt;T, E&gt;</code> this simple?</p><p style="margin:0px 0px 1.2em!important" class="">We can even leave current syntax in place, just <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">T throws E</code> will be a sugar for <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Result&lt;T, E&gt;</code>. Methods of error handling described in <a href="https://github.com/apple/swift/blob/master/docs/ErrorHandling.rst" class="">this manifesto</a> will be represented, respectively, by <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Optional</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Result</code>, and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">fatalError</code>, with all of them defined in the standard library—isn’t that reasonable?</p>
<div title="MDH:VGhpcyBwcm9wb3NhbCBzaG91bGQgYmUgcmV2aWV3ZWQgYXMgYSBwYXJ0IG9mICJ0eXBlZCB0aHJv
d3MiIHByb3Bvc2FsLCB3aXRoIHRoZSBbb3JpZ2luYWwgUFJdKGh0dHBzOi8vZ2l0aHViLmNvbS9h
cHBsZS9zd2lmdC1ldm9sdXRpb24vcHVsbC82OCkgcHJlcGFyZWQgYnkgRGF2aWQgT3dlbnMuPGRp
dj48YnI+PC9kaXY+PGRpdj5UeXBlZCB0aHJvd3Mgd29uJ3QgY2hhbmdlIGFueXRoaW5nIGFib3V0
IGhvdyBtYW55IHR5cGVzIGNh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
aWZlc3RvXShodHRwczovL2dpdGh1Yi5jb20vYXBwbGUvc3dpZnQvYmxvYi9tYXN0ZXIvZG9jcy9F
cnJvckhhbmRsaW5nLnJzdCkgd2lsbCBiZSByZXByZXNlbnRlZCwgcmVzcGVjdGl2ZWx5LCBieSBg
T3B0aW9uYWxgLCBgUmVzdWx0YCwgYW5kIGBmYXRhbEVycm9yYCwgd2l0aCBhbGwgb2YgdGhlbSBk
ZWZpbmVkIGluIHRoZSBzdGFuZGFyZCBsaWJyYXJ5LS1pc24ndCB0aGF0IHJlYXNvbmFibGU/PGJy
PjwvZGl2Pg==" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0" class="">​</div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>