On Eq, was Re: [Haskell-cafe] When to use fancy types [Re:
NumberTheory library]
Jacques Carette
carette at mcmaster.ca
Fri May 13 10:06:00 EDT 2005
Wonderful post! I just want to throw a minor wrench in:
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* !
That is because +0. == -0. is true (according to IEEE 754) but it is legitimate to have functions f where f +0. <> f
-0. [this mostly shows up for complex rather than real functions, but this is still in IEEE 754].
The easiest interpretation is that == as defined in IEEE 754 is not in fact a semantic equality predicate. Very
messy. But having a good language (Haskell) that does not respect established standards (IEEE 754) when it claims to
implement 'floating point' computations is a real drawback.
Jacques
More information about the Haskell-Cafe
mailing list