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

Brian Hulley brianh at metamilk.com
Thu Apr 6 23:33:27 EDT 2006


Brian Hulley wrote:
> John Meacham wrote:
>>[snip]
>> 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.
>
> As Steve and Robert pointed out, you can't always rely on these
> properties (although it is debatable whether or not floats and
> doubles have any useful numeric properties in the first place).

Actually I'm revising my idea about this. I think that Float and Double are 
just intrinsically dangerous numeric types which have members that don't 
satisfy the Eq and Ord equations so their presence doesn't contradict your 
argument in favour of hierarchical classes. It rather suggests that the 
existing hierarchy where Float and Double are instances of RealFloat which 
inherits (indirectly) from Ord is simply wrong, since Float and Double don't 
and can't obey the Ord equations.

Perhaps Float and Double should be moved to a class such as DangerousNum 
which does not inherit from Eq, Ord etc so that it would be clear they can't 
participate in any equational reasoning?

This would require different names for all DangerousNum ops or some way to 
qualify the name of a class member with the class name eg 3.0 DangerousNum£+ 
5.6 (dot can't be used because then DangerousNum would be assumed to be a 
module name)

Stephen Forrest wrote:
> On 4/6/06, Brian Hulley <brianh at metamilk.com> wrote:
>> What about:
>>
>> class Eq a where (==), (/=) :: ...
>> class PartialOrd a where
>>      (<), (>) :: a->a->Bool
>>      x > y = y < x
>>
>> class (PartialOrd a) => TotalOrd a where x <= y = not (y < x) ....
>>    -- => not meaning inheritance but just a restriction on a for use
>> of TotalOrd
>
> A partial order can be defined in either of two ways, both of which
> require some notion of equality.  If it is a weak partial order, you
> need to require reflexivity, i.e. x=y implies R(x,y).  If it is a
> strong partial order, you need to require irreflexivity.  So some
> notion of equality is necessary in either case.  (I think the same is
> true of preorders, if we want to generalize to that.)
>
> So, if such a PartialOrd existed, it really should be between Eq and
> Ord in the class hierarchy.

It seems that there are indeed some hierarchies that are intrinsic and 
therefore I'll have to withdraw my attempt to argue in favour of a flat 
class system! :-)

Thanks to all who replied,

Brian. 



More information about the Haskell-Cafe mailing list