<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:47 AM, David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 Feb 22, 2017, at 8:01 AM, Ben Cohen via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">default</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </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="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// `default` means try </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></div></div></blockquote><br class=""><div>This feature is not strictly required in this case, as we moved away from using `multiplied` of type (Self, Self) -> Self to using proper `static func +`. So the ambiguity will *not* happen in the most common case when you want to multiply two numbers of some type and get the result of the same type. Ambiguity will only become a problem in what I believe to be a very less frequent case, when you want to do something very special, like, catch the overflow explicitly or get the full result in a form of DoubleWidth<T>.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </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="">) -> (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=""> </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="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DoubleWidth</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">></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 </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;"> x = </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: </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;"> (y,overflow) = </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: </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;">// </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;"> z: </span><span class="" style="font-variant-ligatures: no-common-ligatures;">DoubleWidth</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = </span><span class="" style="font-variant-ligatures: no-common-ligatures;">i</span><span class="" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="font-variant-ligatures: no-common-ligatures;">multiplied</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(by: </span><span class="" style="font-variant-ligatures: no-common-ligatures;">j</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div></div><div class=""><br class=""></div><div class="">- Dave Sweeris</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>