<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="">I know, but a simple&nbsp;<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> x = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class="">/</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class=""><br class=""></span></div><div class="">becomes ambiguous which I don’t like.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 13, 2016, at 8:00 PM, Mark Lacey &lt;<a href="mailto:mark.lacey@apple.com" class="">mark.lacey@apple.com</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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Oct 13, 2016, at 5:37 PM, Hooman Mehr via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Oct 13, 2016, at 3:31 PM, Rick Mann via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Would it make sense to be able to specify priority for a set of overloaded methods to help resolve ambiguity?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div></div></div></blockquote><div class=""><br class=""></div>I don’t think we want to head down that route, partially because using a contextual type as mentioned below removes the ambiguity.</div><div class=""><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="">This might be pretty useful in some situations, but I am not sure if the semantic complexity that it introduces is worth it.</div><div class=""><br class=""></div><div class="">Another example of how this could be useful:&nbsp;</div><div class=""><br class=""></div><div class="">I made a bare-bones&nbsp;<a href="https://gist.github.com/hooman/6e08c48e1e06ee19e06e5b09f664f9be" class="">rational number type</a>&nbsp;for Swift a while ago. I would love to be able to overload “/“ operator to create fractions (rational numbers) instead of dividing two integers.&nbsp;</div><div class=""><br class=""></div><div class="">If I overloaded “/“ to return rational (Int / Int -&gt; Rational), the result type of the operator would become ambiguous for every use of it with integer operands.</div></div></div></blockquote><div class=""><br class=""></div><div class="">That isn’t the way the type checker works. If you use an explicit type to contextualize the expression, there is no ambiguity. For example this works without any ambiguity.</div><div class=""><br class=""></div><div class=""><div class="">struct Rational {}</div><div class="">func / (lhs: Int, rhs: Int) -&gt; Rational { return Rational() }</div><div class="">func + (lhs: Rational, rhs: Rational) -&gt; Rational { return Rational() }</div><div class=""><br class=""></div><div class="">func use(r: Rational) {}</div><div class=""><br class=""></div><div class="">let x: Rational = (1 / 2) + (2 / 3) &nbsp;// Rational result type, no ambiguity</div><div class="">use(r: (1 / 2) + (2 / 3)) &nbsp;// Rational argument type, no ambiguity</div><div class=""><div class="">let y = (1 / 2) as Rational &nbsp; &nbsp;// Calls func/(Int,Int)-&gt;Rational</div></div><div class=""><br class=""></div><div class="">Mark</div></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=""> It would be nice if I could prioritize my overload of “/“ over stdlib definition to resolve the ambiguity.&nbsp;</div><div class=""><br class=""></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></body></html>