[Haskell] compares :: Ord a => a -> a -> Ordering -> Ordering

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Tue Feb 14 20:17:43 EST 2006


I just realized that the class Ord should have an additional method:

   class Eq a => Ord a where
     compares :: a -> a -> Ordering -> Ordering
     compares x y d = case compare x y of { EQ -> d ; o -> o }
     ...

This would make writing Ord instances much easier:

   instance (Ord a, Ord b, Ord c, Ord d) => Ord (a,b,c,d) where
     compares (a1,b1,c1,d1) (a2,b2,c2,d2) =
       compares a1 a2 . compares b1 b2 . compares c1 c2 . compares d1 d2

-- Ben



More information about the Haskell mailing list