Defining Ord itself in the standard prelude requires an instance of Eq :
class (Eq a) => Ord a where ...
So it would be wrong to break
x == y = compare xy == EQ x /= y = compare xy /= EQ
As it would be violated (from the default definitions for these operators in Ord).
x <= y = compare xy /= GT x < y = compare xy == LT x >= y = compare xy /= LT x > y = compare xy == GT
Edit: use in libraries
I would be surprised if the standard libraries did not use the Ord == and /= operators. Specific operators ( == , /= , <= , < , >= , > ) are often more convenient than compare , so I expect them to be used in the code for map or filter s.
You can see that == used by key guards in Data.Map in fromAscListWithKey . This specific function only calls the Eq , but if the key is also an Ord instance, Ord compare will be used for other functions of the resulting map , which is the assumption that Eq == matches Ord compare and is tested for Eq .
As a library programmer, I would not be surprised if any of the special-purpose operators outperformed compare for a specific purpose. After all, why are they part of the Eq and Ord classes instead of being defined as polymorphic for all Eq or Ord instances. I could use them even when compare more convenient. If I did this, I would probably define something like:
compareOp :: (Ord a) => Ordering -> Bool -> a -> a -> Bool compareOp EQ True = (==) compareOp EQ False = (/=) compareOp LT True = (<) compareOp LT False = (>=) compareOp GT True = (>) compareOp GT False = (<=)
source share