Add Ord Laws to next Haskell Report

Henning Thielemann lemming at henning-thielemann.de
Fri Feb 8 09:54:29 UTC 2019


On Fri, 8 Feb 2019, Oliver Charles wrote:

> On Fri, 8 Feb 2019, 12:20 am Henning Thielemann, <lemming at henning-thielemann.de> wrote:
>
>       On Thu, 7 Feb 2019, Andrew Butterfield wrote:
>
>       > Imagine trying to define the obvious partial ordering on sets - i.e.
>       > subset-or-equal using the Ord class. What should be the result, for
>       > Instance Ord (Set Int) of
>       >
>       > compare (fromList [1]) (fromList [2])    or  fromList [2] <= fromList [1] ?
>
>       Partial ordering means to me that the comparison function is partial.
>       I.e. fromList [2] <= fromList [1] would be "undefined".__________________
> 
> 
> Oh heavens no! It's very useful to ask whether two elements are comparable, that's  a nightmare with this
> approach.

With the signature of 'compare' we can hardly do it better. That's why it 
is certainly better to leave Ord for total orderings and define

class PartialOrd a where
    maybeCompare :: a -> a -> Maybe Ordering


More information about the Libraries mailing list