Add Ord Laws to next Haskell Report

Tikhon Jelvis tikhon at jelv.is
Wed Feb 6 21:02:38 UTC 2019


Does the wording of the report specify "totally ordered" as a law? I think
it would be good to make that explicit, laying out the axioms for what a
total order is—similar to the current documentation in Data.Ord but
explicitly as the laws for the class.

The relationship between Eq and Ord should be explicitly specified too, if
it isn't.

On Wed, Feb 6, 2019, 12:53 Herbert Valerio Riedel <hvriedel at gmail.com wrote:

>
>
>
>
> On Wed, Feb 6, 2019 at 9:43 PM chessai . <chessai1996 at gmail.com> wrote:
>
>> Per GHC.Classes (haddock-viewable from Data.Ord)
>>
>> "The Haskell Report defines no laws for Ord. However, <= is
>> customarily expected to implement a non-strict partial order and have
>> the following properties:"
>>
>> I propose that in the next report that the expected typeclass laws for
>> Ord be added. They're generally agreed upon/understood.
>>
>
>
> Can you spell out the concrete change to the report wording you're
> suggesting? For reference, the current wording used in the 2010 Haskell
> Report is quoted below. While at it, you might also want to take into
> account the `Eq` class definition in the report.
>
>
> 6.3.2 The Ord Class
>
>   class  (Eq a) => Ord a  where
>     compare              :: a -> a -> Ordering
>     (<), (<=), (>=), (>) :: a -> a -> Bool
>     max, min             :: a -> a -> a
>
>     compare x y | x == y    = EQ
>                 | x <= y    = LT
>                 | otherwise = GT
>
>     x <= y  = compare x y /= GT
>     x <  y  = compare x y == LT
>     x >= y  = compare x y /= LT
>     x >  y  = compare x y == GT
>
>     -- Note that (min x y, max x y) = (x,y) or (y,x)
>     max x y | x <= y    =  y
>             | otherwise =  x
>     min x y | x <= y    =  x
>             | otherwise =  y
>
> The Ord class is used for totally ordered datatypes. All basic datatypes
> except for functions, IO, and IOError, are instances of this class.
> Instances of Ord can be derived for any user-defined datatype whose
> constituent types are in Ord. The declared order of the constructors in
> the data declaration determines the ordering in derived Ord instances.
> The Ordering datatype allows a single comparison to determine the precise
> ordering of two objects.
>
> The default declarations allow a user to create an Ord instance either
> with a type-specific compare function or with type-specific == and <=
> functions.
>
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190206/2d627744/attachment.html>


More information about the Libraries mailing list