WAT: opCmp and opEquals woes

Manu via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 25 20:47:20 PDT 2014


On 26 July 2014 06:35, Walter Bright via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On 7/25/2014 5:10 AM, Ary Borenszweig wrote:
>
>> Not at all.
>>
>> If you have a type that has partial ordering (only cares about opCmp, not
>> about
>> opEquals), but still keeps the default opEquals, then this would silently
>> break
>> someone's code by changing their opEquals semantic.
>>
>> THIS is the breaking change.
>>
>
> Yes. A subtle but extremely important point. Comparison and Equality are
> fundamentally different operations. Defining opEquals to be the equivalent
> of opCmp==0 is utterly breaking that.
>

Perhaps the problem here is that there is a missing concept.
There is equality and equivalence, and only equivalence is expressed in D
(ie, the one that is relevant among the suite of comparison operations).

Would you argue that == and != are unrelated, distinct and separate
operations from <,<=,>=,>, and they should never be used in conjunction, or
assumed to be related?
I think any reasonable person will assume that the suite of comparisons are
related operations.
So perhaps === is missing, and that's what should be used for AA's, and
also the thing that actually matches the compiler's generated opEquals...?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140726/96ee3e4f/attachment.html>


More information about the Digitalmars-d mailing list