[swift-evolution] [Draft][Proposal] Formalized Ordering

Dmitri Gribenko gribozavr at gmail.com
Fri Jul 22 02:32:35 CDT 2016


On Fri, Jul 22, 2016 at 12:29 AM, David Hart <david at hartbit.com> wrote:
> Just trying to summarize to make sure I understand. So, on most Equatable
> types, == and areSame will have the same semantics (return the same result
> for all operations), but some types will want different semantics, and
> that's why areSame is introduced.
>
> Correct?

Correct.

Note that only the `areSame()` function is the Equatable requirement.
For `==`, there will be a global generic operator, that will just
forward to `areSame()`.  Individual types can add their own overloads
of `==` which will be preferred over the generic `==` due to overload
resolution rules.

> If that's the case, I'm a bit perplexed on what types would want different
> semantics for == and areSame. Is FloatingPoint one of them? Is that why NaN
> is brought up in the Motivation section?

Yes, floating point types are a good example.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list