<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">I also thought about sum types as implementation of errors, but selecting between Tyler’s and John’s syntaxes, I would pick the latter. Compare:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" 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;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x: (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> a: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) -&gt; (<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span> | (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> b: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Float</span>) -&gt; (<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span> | <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Double</span>))

<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x: (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> a: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) throws(<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span>) -&gt; (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> b: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Float</span>) throws(<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span>) -&gt; <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Double</span>

<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x: (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> a: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) -&gt; (<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span> | <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Double</span>)

<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x: (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> a: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) throws(<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span>) -&gt; <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Double</span>
</code></pre>
<p style="margin:0px 0px 1.2em!important">Granted, the version with sum types contains less characters and leads to more minimalistic type system. But <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">|</code> on itself does not mean error handling. It’s used for creation of sum types, without error handling semantics. So it’s easier to grasp the meaning of type containing <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">throws</code> than anything else. If Swift had a special symbol as related to errors, as <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">?</code> relates to optionals, then we could use it there. Unfortunately, there isn’t anything like that.</p>
<blockquote style="margin:1.2em 0px;border-left:4px solid rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:0px 0px 1.2em!important">What would it look like if the function returns nothing but can throw an error?</p>
</blockquote>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" 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;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x: (<span class="hljs-number" style="color:rgb(0,128,128)">_</span> a: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) -&gt; (<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Error</span> | ())
</code></pre>
<div title="MDH:PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEiPjxkaXYgY2xhc3M9ImdtYWlsX3F1b3RlIj48ZGl2Pkkg
YWxzbyB0aG91Z2h0IGFib3V0IHN1bSB0eXBlcyBhcyBpbXBsZW1lbnRhdGlvbiBvZiBlcnJvcnMs
IGJ1dCBzZWxlY3RpbmcgYmV0d2VlbiBUeWxlcidzIGFuZCBKb2huJ3Mgc3ludGF4ZXMsIEkgd291
bGQgcGljayB0aGUgbGF0dGVyLiBDb21wYXJlOjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+YGBg
c3dpZnQ8L2Rpdj48ZGl2PmxldCB4OiAoXyBhOiBJbnQpIC0mZ3Q7IChFcnJvciB8IChfIGI6IEZs
b2F0KSAtJmd0OyAoRXJyb3IgfCBEb3VibGUpKTwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+bGV0
IHg6IChfIGE6IEludCkgdGhyb3dzKEVycm9yKSAtJmd0OyAoXyBiOiBGbG9hdCkgdGhyb3dzKEVy
cm9yKSAtJmd0OyBEb3VibGU8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2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