[Haskell-cafe] Re: Justification for Ord inheriting from Eq?

Christian Maeder maeder at tzi.de
Fri Apr 7 04:58:23 EDT 2006

John Meacham wrote:
> 1. one really does logically derive from the other, Eq and Ord are like
> this, the rules of Eq says it must be an equivalance relation and that
> Ord defines a total order over that equivalance relation. this is a good
> thing, as it lets you write code that depends on these properties.

given an Ord instance (for a type T) a corresponding Eq instance can be 
given by:

instance Eq T where
    a == b = compare a b == EQ

This does not make the definition of an Ord instance (that is supposed 
to match an equivalence) easier but ensures at least the required 

I never dared to define this generically and switch on various ghc 

instance Ord a => Eq a where ...

It just strikes me that wrt. "NaN" the Ord instances for Float and 
Double are no total orders (and thus these types are not suited for 
sets, i.e. "Data.Set.Set Float")

Cheers Christian

More information about the Haskell-Cafe mailing list