[Haskell-cafe] Re: NaN, Infinity literals

Arie Peterson ariep at xs4all.nl
Sat Sep 9 19:23:55 EDT 2006

Ashley Yakeley wrote:

> Bertram Felgenhauer wrote:
>> This is correct according to the IEEE 754 standard, which defines
>> that NaN compares unequal to everything, including itself.
> This is numerically useful, perhaps, but nonetheless disturbing. For it
> would be helpful to expect that any type that presumes to be an instance
> of Eq has a == a = True.
> There really are two different notions of equality here. Perhaps they
> should be given two different names in the language?

I think that the problem is not in equality, but in NaN: equality on
numbers makes perfect sense (although rounding/lack of precision can
render it useless), but NaN is *not a number*, so you can't properly
compare it with numbers.

IMO, NaN should not have the same type as real numbers; illegal operations
should return NaN in the form of an error in some monad or by raising an
exception (I don't know the behaviour of NaN in other aspects, but this
strange equality sounds like propagation of errors/exceptions).



More information about the Haskell-Cafe mailing list