[Haskell-cafe] Justification for Ord inheriting from Eq?
brianh at metamilk.com
Thu Apr 6 16:31:24 EDT 2006
I've been wondering for a long time if there is a reason why Ord should
inherit from Eq and not vice versa, or whether in fact there is any
justification for making either Ord or Eq inherit from the other one.
For example, Ord and Eq could alternatively be defined as:
class Ord a where
(<), (<=), (>=), (>) : a -> a -> Bool
x <= y = not (y < x)
x >= y = not (x < y)
x > y = y < x
class Ord a => Eq a where
(==), (/=) :: a -> a -> Bool
x /= y = x < y || y < x
x == y = not (x /= y)
Part of the reason for my question is that it seems to me that the lesson
from object oriented programming is that inheritance is usually a bad idea,
since very few things (perhaps nothing?) have a single natural taxonomy
(witness the efforts to reorganise the numeric hierarchy that have been
alluded to on this list).
In languages such as C++ the only "good" use of inheritance seems to be when
you have an abstract base class representing an interface and multiple
concrete derived classes (as immediate children of it) representing the
implementations, but in Haskell, this is the class/instance distinction, so
I can't see a strong reason why Haskell classes should be allowed to inherit
from other classes.
Except perhaps Monad, MonadIO, MonadPlus etc...
More information about the Haskell-Cafe