Proposal: New Eq and Ord instances for Double and Float

Felipe Almeida Lessa felipe.lessa at
Mon Sep 26 12:21:56 CEST 2011

On Mon, Sep 26, 2011 at 6:53 AM, Roman Leshchinskiy <rl at> wrote:
> IMO, anybody who stores Doubles in a Set either really knows what he's
> doing (in which case NaNs shouldn't be a problem) or is just doing it
> wrong.
> In general, these examples just look broken to me regardless of how Eq and
> Ord are defined. If I saw something like this happen in real code I'd
> assume it's a bug.

At the very least there should be more documentation about this
problem (I don't know where).  Even for those who know about the IEEE
standard, it's not obvious at all that these functions won't work.
The more complex the example (max → sort → Data.Set), the less
straightforward the problem becomes.

Instead of this proposal, it may also be interesting to propose something like

  newtype Total a = Total a

  type TotalDouble = Total Double
  type TotalFloat = Total Float

which provides meaningful Eq and Ord instances for algorithms that
don't care about what a NaN is.



More information about the Libraries mailing list