Expected behavior of "deriving Ord"?

Conal Elliott conal at conal.net
Thu Mar 20 13:28:26 EDT 2008

AddBounds makes total orders from total orders.  It just adds new least and
greatest elements.

The problem with the derived instance is that it doesn't exploit the
potential laziness of min on 'a'.  Because of their types, min it can
produce partial info from partial info and (<=) and compares cannot.

  - Conal

On Thu, Mar 20, 2008 at 2:00 AM, Christian Maeder <Christian.Maeder at dfki.de>

> Conal Elliott wrote:
> > I have an algebraic data type (not newtype) that derives Ord:
> >
> >     data AddBounds a = MinBound | NoBound a | MaxBound
> >         deriving (Eq, Ord, Read, Show)
> The class Ord is not suited for partial orders. If you write your own
> Ord instances anyway, I'd suggest to introduce a proper new class (say
> Lattice), too!
> I hope that the computation of "uncomparable" does terminate in your
> case. Maybe the lattice operation "join and "meet" are even more
> appropriate than "min" and "max".
> However, if your type parameter "a" has a total order, the above derived
> instance looks correct.
> HTH Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20080320/d2ea114e/attachment-0001.htm

More information about the Glasgow-haskell-users mailing list