<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><pre style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg">@unwrappable(type: Int)
public enum Count {
case none // not unwrappable
case many // not unwrappable
case some(Int)
case owed(Int)
case something(String) // not unwrappable
case multiple(Int, Int) // not unwrappable
}
</code></pre></div>
</div></blockquote><p></p></div><p style="margin:0px 0px 1.2em!important"></p>
<p style="margin:0px 0px 1.2em!important">Instead of requiring the <code style="font-size:1em;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">@unwrappable</code> attribute, why not have <code style="font-size:1em;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">unwrap</code> work normally when the type can be inferred, or require hints when it can’t:</p>
<pre style="font-size:1em;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:1em;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) none repeat scroll 0% 0%"><span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// For an optional (or any other enum with only one wrapped type)</span>
guard unwrap x <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">return</span> }
<span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// For an enum of type Count as defined above</span>
guard unwrap myCount <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// compiler error - type can't be determined</span>
guard unwrap(myCount: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// Success for 'some' or 'owed' (implicit shadowing)</span>
guard unwrap(<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> someOrOwed: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) myCount <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// Success for 'some' or 'owed' (no shadowing)</span>
guard unwrap(<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>, <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> y: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) myCount <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// Success for 'multiple' (no shadowing)</span>
</code></pre>
<p style="margin:0px 0px 1.2em!important">Notes:</p>
<ul style="margin:1.2em 0px;padding-left:2em">
<li style="margin:0.5em 0px"><code style="font-size:1em;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">unwrap x</code> is equivalent to <code style="font-size:1em;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">unwrap(x: T)</code> where there is a single unambiguous type.</li>
<li style="margin:0.5em 0px">The <code style="font-size:1em;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">let</code> keyword probably could be implicit for the non-shadowing forms, like it is for the shadowing form, but makes it clear what’s going on.</li>
<li style="margin:0.5em 0px">unwrap fails for <code style="font-size:1em;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">none</code> or <code style="font-size:1em;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">many</code> from the <code style="font-size:1em;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">Count</code> type, just as it does for <code style="font-size:1em;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">none</code> from Optional</li>
<li style="margin:0.5em 0px">I <em>think</em> that this assumes Swift is not allowed to try to infer the most restrictive type for reference types. Haven’t really thought about this much.</li>
</ul>
<div title="MDH:PGNvZGUgc3R5bGU9ImJveC1zaXppbmc6Ym9yZGVyLWJveDtmb250LWZhbWlseTpDb25zb2xhcywn
TGliZXJhdGlvbiBNb25vJyxNZW5sbyxDb3VyaWVyLG1vbm9zcGFjZTtwYWRkaW5nOjBweDttYXJn
aW46MHB4O2JhY2tncm91bmQtY29sb3I6dHJhbnNwYXJlbnQ7Ym9yZGVyLXRvcC1sZWZ0LXJhZGl1
czozcHg7Ym9yZGVyLXRvcC1yaWdodC1yYWRpdXM6M3B4O2JvcmRlci1ib3R0b20tcmlnaHQtcmFk
aXVzOjNweDtib3JkZXItYm90dG9tLWxlZnQtcmFkaXVzOjNweDt3b3JkLWJyZWFrOm5vcm1hbDti
b3JkZXI6MHB4O2Rpc3BsYXk6aW5saW5lO292ZXJmbG93OnZpc2libGU7bGluZS1oZWlnaHQ6aW5o
ZXJpdDt3b3JkLXdyYXA6bm9ybWFsIiBjbGFzcz0iZ21haWxfbXNnIj48L2NvZGU+PGRpdiBjbGFz
cz0iZ21haWxfcXVvdGUiPjxibG9ja3F1b3RlIGNsYXNzPSJnbWFpbF9xdW90ZSIgc3R5bGU9Im1h
cmdpbjowIDAgMCAuOGV4O2JvcmRlci1sZWZ0OjFweCAjY2NjIHNvbGlkO3BhZGRpbmctbGVmdDox
ZXg7Ij48ZGl2IHN0eWxlPSJ3b3JkLXdyYXA6YnJlYWstd29y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