<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 Apr 16, 2017, at 11:52 AM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Sun, Apr 16, 2017 at 12:58 PM, Jonathan Hull <span dir="ltr" class=""><<a href="mailto:jhull@gbis.com" target="_blank" class="">jhull@gbis.com</a>></span> wrote:<br class=""><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" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Apr 16, 2017, at 10:45 AM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_6646175237874714548Apple-interchange-newline"><div class=""><div dir="ltr" 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" class="">On Sun, Apr 16, 2017 at 12:35 PM, Jonathan Hull via swift-evolution<span class="m_6646175237874714548Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-<wbr class="">evolution@swift.org</a>></span><span class="m_6646175237874714548Apple-converted-space"> </span>wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class="">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 class=""><br class=""></div><div class="">Right, but I'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></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">That is why there is a default metric. For most uses, what you suggest (i.e. trapping on NaN) makes sense, and that would be the default. Someone may have a need to compare in a way which differentiates NaN or matches a different IEEE level, and they can create a metric that provides that comparison, and still be able to use it with all of the algorithms in the standard library. (Note: I see those alternate metrics as living in a library as opposed to the standard library)</div></div></div></blockquote><div class=""><br class=""></div><div class="">FloatingPoint already exposes IEEE total ordering as `isTotallyOrdered`. You can use it in `sort(by:)`. That's not what I'm talking about.</div><div class=""><br class=""></div><div class="">This proposal is about the design of `Comparable`. My concern is about `<` giving different answers depending on surrounding code. I don't see the point of it. Do you?</div></div></div></div></div></blockquote><div><br class=""></div><div>I agree that ‘<‘ should be consistent.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><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" class=""><div class=""><div class="">It is clear that we will need multiple comparison metrics for some types (e.g. Case/Diacritic insensitive compare), and I am suggesting we formalize that so we don’t end up with a bunch of random ‘compare(with: optionA: optionB:)’ functions which are incompatible across types.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Since the String overhaul is not done, and since localized comparison has been explicitly deferred from even the current scope of the String overhaul, I don't see how we can design around this with any sort of insight.</div></div></div></div></blockquote><div><br class=""></div><div>The point is to architect away the need to know specifics ahead of time. This should work regardless of how those end up being implemented.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">In any case, again, I'm speaking specifically about the proposed design of `Comparable`. Do you think that there are meaningful generic algorithms to be written over localized string comparison and floating point comparison which are not possible today, which requires a redesign of `Comparable`?</div></div></div></div></blockquote><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>sort(.ascending, using: metric) //This is defined on collection, but works with case sensitive or insensitive, diacritics, IEEE ordering, etc… It basically works for all options</div><div><br class=""></div><div>It would also be fairly easy to combine with the new key paths to create composable sort descriptors.</div><div><br class=""></div><div>Note: If you look at my design again, you will notice it isn’t really a redesign of Comparable. Instead, it mainly adds a new protocol defining a comparison metric. Compare is left alone except for gaining a defaultMetric property (which has a default implementation that calls ‘<‘ & ‘==‘). It also gains a couple of convenience methods (and convenience operator '<=>’) which can be added post-hoc. All Swift 3 code would continue working unaltered. It simply gives the option of extra efficiency and flexibility when desired.</div><div><br class=""></div><div>Thanks,</div><div>Jon</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><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" class=""><div class=""><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" 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" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="m_6646175237874714548h5"><div class="">On Apr 13, 2017, at 8:30 PM, Jonathan Hull via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class="m_6646175237874714548m_-3089135546296383232Apple-interchange-newline"></div></div><div class=""><div class=""><div class="m_6646175237874714548h5"><div style="word-wrap:break-word" class="">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 class=""><br class=""></div><div class="">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 ‘<‘ and ‘==‘ to provide a comparison result.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 <=>, which both use the default metric.</div><div class=""><br class=""></div><div class="">Pros:</div><div class="">• Would work without compiler alterations</div><div class="">• You can create metrics that compare items of different types</div><div class="">• Can setup the metric once for algorithms/comparisons with high setup cost</div><div class="">• Things like 'compare(to: other, using: .caseInsensitiveComparison)' fall out of the design without having to create/learn various different versions of compare on different types.</div><div class="">• Spaceship operator <=> for those who want it</div><div class="">• 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 class=""><br class=""></div><div class="">Cons:</div><div class="">• More protocols defined by the design</div><div class="">• Requires an extra struct/class to implement in non-standard cases (e.g. case insensitive compare)</div><div class="">• Probably something else I am missing</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 13, 2017, at 1:24 PM, Ben Cohen via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class="m_6646175237874714548m_-3089135546296383232Apple-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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">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" class=""><br class=""></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" class=""><a href="https://github.com/airspeedswift/swift-evolution/blob/fa007138a54895e94d22e053122ca24ffa0b2eeb/proposals/NNNN-ComparisonReform.md" target="_blank" class="">https://github.com/airspeedswi<wbr class="">ft/swift-evolution/blob/fa0071<wbr class="">38a54895e94d22e053122ca24ffa0b<wbr class="">2eeb/proposals/NNNN-Comparison<wbr class="">Reform.md</a></div></div></blockquote></div><br class=""></div></div></div></div></div><span class="">______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-evolution</a><br class=""></span></div></blockquote></div><br class=""></div></div></div><br class="">______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-evolution</a></blockquote></div></div></div></div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""></div></div>
</blockquote></div><br class=""></body></html>