<div dir="ltr">On Sun, Apr 16, 2017 at 12:35 PM, Jonathan Hull via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">One benefit of the idea of using comparison metrics instead of changing comparable, is that you could just have two metrics on double.  The default one which is closer to what we have now (or the new thing Xiaodi suggested with trapping NaN), and one which matches IEEE.  You could in fact make a metric for each level if desired.</div></blockquote><div><br></div><div>Right, but I&#39;m arguing that having multiple comparison metrics is _undesirable_. I see the need for one design that can accommodate unordered comparisons. I do not see the need for a second comparison metric.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Thanks,</div><div>Jon<br><div><br><div><blockquote type="cite"><div><div class="h5"><div>On Apr 13, 2017, at 8:30 PM, Jonathan Hull via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-3089135546296383232Apple-interchange-newline"></div></div><div><div><div class="h5"><div style="word-wrap:break-word">One more thought.  I am generally in favor of this proposal, but since it is in the pitch stage, I wanted to offer an alternative approach that I didn’t see mentioned.  Food for thought/discussion.<div><br></div><div>What if, instead of repurposing comparable (and adding new functions for options like case insensitive compare), we define a comparison metric (with all of the options built in) and then use that to get our comparison result.  Comparable things would have a default metric that uses ‘&lt;‘ and ‘==‘ to provide a comparison result.</div><div><br></div><div>The metric would have a method which takes two things and returns a ComparisonResult. The two things would usually be the same type, but wouldn’t necessarily have to be.</div><div><br></div><div>As a convenience, any type could have a compared(to:, using:) method where you pass a comparison metric to the using parameter and receive a ComparisonResult.  Comparable things could add a compared(with:) method and the spaceship operator &lt;=&gt;, which both use the default metric.</div><div><br></div><div>Pros:</div><div>• Would work without compiler alterations</div><div>• You can create metrics that compare items of different types</div><div>• Can setup the metric once for algorithms/comparisons with high setup cost</div><div>• Things like &#39;compare(to: other, using: .caseInsensitiveComparison)&#39; fall out of the design without having to create/learn various different versions of compare on different types.</div><div>• Spaceship operator &lt;=&gt; for those who want it</div><div>• In some cases, it can provide a much more efficient implementation based on underlying structure. For example, you can get a metric from String/Unicode which is optimized for a particular view of that string (say ASCII).  Depending on the case, when one of the objects doesn’t match the optimized type, it can either convert or fallback to a more general algorithm… but it should provide a pretty big win when most of the objects have a known structure.</div><div><br></div><div>Cons:</div><div>• More protocols defined by the design</div><div>• Requires an extra struct/class to implement in non-standard cases (e.g. case insensitive compare)</div><div>• Probably something else I am missing</div><div><br></div><div>Thanks,</div><div>Jon</div><div><div><br></div><div><br></div><div><br><div><blockquote type="cite"><div>On Apr 13, 2017, at 1:24 PM, Ben Cohen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-3089135546296383232Apple-interchange-newline"><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Online copy here:</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://github.com/airspeedswift/swift-evolution/blob/fa007138a54895e94d22e053122ca24ffa0b2eeb/proposals/NNNN-ComparisonReform.md" target="_blank">https://github.com/<wbr>airspeedswift/swift-evolution/<wbr>blob/<wbr>fa007138a54895e94d22e053122ca2<wbr>4ffa0b2eeb/proposals/NNNN-<wbr>ComparisonReform.md</a></div></div></blockquote></div><br></div></div></div></div></div><span class="">______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></span></div></blockquote></div><br></div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>