Here are some comments perhaps relevant to the Haskell prelude.
I'd like to see a distinction made between partial and total
orderings. In mathematics, there is little difference but in computing
the difference can be significant, e.g. many sorting algorithms require
a total ordering rather than a partial ordering.
At present, it is quite easy to define a partial ordering e.g. the subset
relation and use this as the basis for an instance of class Ord. It is also
possible to base sorting on (<) from class Ord. This easily produces wrong
results.
As an example, try using ordered lists with duplicates eliminated to
represent sets. There are two interpretations of (<) in this context:
the lexographical ordering is needed to order sets of sets represented
this way; using (<) to mean set inclusion might produce errors in the
sorting/merging needed to represent sets of sets.
My suggestion is that class Ord be built around a comparison operation
which produces -1, 0 or 1 depending on the result of the comparison.
That Ord be reserved for total orderings and that a new class name be
used for partial orders.
In Gofer, this leads to some apparent efficiencies. List and similar
complex comparisons are more efficient:
instance Ord a => Ord [a] where
cmp (x:xs) (y:ys) = let t=cmp x y in case t of 0->cmp xs ys; _ -> t
when x and y are complex this avoids calculating both x==y and x<=y.
In this case, I don't derive class Ord from class Eq, rather class
Eq is independant by can be instantiated from an instance of Ord,
hence:
instance Ord a => Eq a where x==y = case cmp x y of 0 -> True ; _ -> False
I'm not sure how well this fits with Haskell. It could complicate derived
instances. I simply put this up for discussion.
regards
b++
_______________________________________________________________________
Bob Buckley Phone: +61 8 302 3465
School of Computer and Information Science Fax: +61 8 302 3381
University of South Australia, The Levels,
Pooraka, SA 5095, Australia email: [EMAIL PROTECTED]