Rich Comparisons Gotcha

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Jan 6 03:16:50 CET 2009


On Tue, 06 Jan 2009 01:24:58 +0000, Mark Wooding wrote:

> Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> wrote:
> 
>> I've already mentioned NaNs. Sentinel values also sometimes need to
>> compare not equal with themselves. Forcing them to compare equal will
>> cause breakage.
> 
> There's a conflict between such domain-specific considerations (NaNs,
> strange sentinels, SAGE's equations), and relatively natural assumptions
> about an == operator, such as it being an equivalence relation.

Such assumptions only hold under particular domains though. You can't 
assume equality is an equivalence relation once you start thinking about 
arbitrary domains.


> I don't know how to resolve this conflict without introducing a new
> function which is (or at least strongly encourages developers to arrange
> for it to be) an equivalence relation.

But there cannot be any such function which is a domain-independent 
equivalence relation, not if we're talking about arbitrarily wacky 
domains. Even something as straight-forward as "is" can't be an 
equivalence relation under a domain where identity isn't well-defined.


-- 
Steven



More information about the Python-list mailing list