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

Robert Dockins robdockins at fastmail.fm
Thu Apr 6 19:00:43 EDT 2006

On Thursday 06 April 2006 06:44 pm, John Meacham wrote:
> On Thu, Apr 06, 2006 at 10:52:52PM +0100, Brian Hulley wrote:

[snip a question about Eq and Ord classes]

> well, there are a few reasons you would want to use inheritance in
> haskell, some good, some bad.
> 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.


Many of you probably know this already, but for those who might not know:

Prelude> let x = read "NaN" :: Float
Prelude> x == x
Prelude> x == 0
Prelude> 0 < x
Prelude> x < 0

Ewwwwww! Be careful how far you depend on properties of typeclasses, and make 
sure you document it when you do.

<we now return to you regularly scheduled discussion>

Rob Dockins

More information about the Haskell-Cafe mailing list