On Eq, was Re: [Haskell-cafe] When to use fancy types [Re: NumberTheory library]

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri May 13 11:47:55 EDT 2005


"Jacques Carette" <carette at mcmaster.ca> writes:

> ajb at spamcop.net wrote:
>> "Eq" is not merely a function of type a -> a -> Bool.  It's a concept
>> with semantics.  It must be an equivalence relation, and it also must
>> mean semantic equality.  Functions that respect semantic equality have
>> the property that x == y implies f x == f y.
>> (No, none of these restrictions are in the language report.  But I'd
>> be annoyed if someone defined a version of Eq that didn't have these
>> properties.)
>
>  From what you argue above, and reading the IEEE 754 standard correctly,
> instance Eq Float and instance Eq Double should be *removed* !

For me this indicates that the above is false. It's almost true but
not strictly true.

It's like the fact that "m >>= return" is the same as m. This almost
holds, except for some monads when m is bottom. It doesn't mean that
instance Monad IO should be removed, but that the real world is not
as ideal as our models suggest.

Removing instance Eq Double would force removing instances for Ord,
Num and all other numeric classes, which is unnacceptable. There
would be no instances of Floating left.

BTW, OCaml recently removed pointer equality check from its
implementation of structural equality, because this caused
inconsistent results for floats which depended on optimization
(a NaN was equal to itself or not depending on whether the compiler
knew the type statically or called the general polymorphic equality
function).

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Haskell-Cafe mailing list