<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 Feb 22, 2017, at 8:01 AM, Ben Cohen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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="">There is another option to avoid the extra types, which is to stop trying to force the disambiguation through argument labels, accept an ambiguous call and have the context disambiguate:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// compilation error: ambiguous</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> x = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class="">.multiplied(by: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">j</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// unambiguously overflow-checked</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (y,overflow) = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">multiplied</span><span style="font-variant-ligatures: no-common-ligatures" class="">(by: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">j</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// unambiguously full-width</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> z: </span><span style="font-variant-ligatures: no-common-ligatures" class="">DoubleWidth</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures" class="">i</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">multiplied</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(by: </span><span style="font-variant-ligatures: no-common-ligatures" class="">j</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="">Ambiguity is bad when you want to distinguish between the “usual one” versus other more specialized versions. So if you really had a regular trapping `adding`, but then also wanted to accommodate the overflow-reporting version when a user explicitly requests it, then the argument label is a clear win. This is a slightly bogus example though, because we explicitly don’t have things like `adding`, we have a `static +` instead. Where the disambiguation is needed is instead between two less common variants as described above.</div></div></div></div></blockquote></div><br class=""><div class="">It’d need a new language feature to support it, but what having “default” resolutions for overloaded functions?</div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">default</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> multiplied(by other: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// `default` means try&nbsp;</span>resolving ambiguities with this version first. The overloaded versions are only considered if the type-checker can’t make this version work.</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> multiplied(by other: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; (partialValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, overflow: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">ArithmeticOverflow</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> multiplied(by other: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DoubleWidth</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">&gt;</span></div></div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;">// signature matches default implementation, use that&nbsp;</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;x =&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">i</span><span class="" style="font-variant-ligatures: no-common-ligatures;">.multiplied(by:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">j</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;">// default version doesn’t return a tuple, so try the overloads… matches the overflow-checked function</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;(y,overflow) =&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">i</span><span class="" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">multiplied</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(by:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">j</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;">//&nbsp;</span>default version doesn’t return a DoubleWidth, so try the overloads… matches the double-width function</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">&nbsp;z:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">DoubleWidth</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">&nbsp;=&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">i</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">.</span><span class="" style="font-variant-ligatures: no-common-ligatures;">multiplied</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">(by:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">j</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">)</span></div></div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></body></html>