[Haskell-cafe] Learn You a Haskell for Great Good - a few doubts

Richard O'Keefe ok at cs.otago.ac.nz
Mon Mar 7 05:55:41 CET 2011

On 7/03/2011, at 5:38 PM, Karthick Gururaj wrote:
> Defn 1. Given four arbitrary a, b, c and d on a set X which is an
> instance of Ord (so a = b, a > b and a < b are defined), let:
>   (a, b) > (c, d) iff a > c  (GT)
>   (a, b) < (c, d) iff a < c  (LT)
>   (a, b) = (c, d) iff a = c. (EQ)
> (please note that I'm redefining the EQ for pairs as well).

Yes, I noted that.  I'm painfully familiar with that ordering
from Smalltalk.  (See LookupKey and Association.)
> Of course, the definition of EQ here is not what would be considered
> "reasonable".

Exactly so.

> I also see now, as I'm typing this, if we define EQ to
> be the way it is in Haskell (which IS the reasonable way), then none
> of my definitions of GT/LT will hold.

I may not have made it sufficiently clear when I mentioned Eq that I
meant "the definitions of Eq for tuples that come standard with Haskell".

> The confusion started for me as I thought of n-tuples as vectors in
> n-dimensional space, on which one doesn't usually define GT and LT
> operators. Now I see some light :)
Well, in n-dimensional space you are usually dealing with X  for some
base set X.  With a tuple (T1,...,Tn) the types T1,...,Tn are
often completely different.

For what it's worth, you _can_ define < on n-dimensional spaces,
and lexicographic order is a popular way to do it.  You can even
put a total order on polynomials in a finite number of variables,
provided the coefficients come from an ordered set.

More information about the Haskell-Cafe mailing list