Ralf Hinze wrote:
> As it stands `sortBy' is more general than `sort': I can define `sort'
> in terms of `sortBy' but not the other way round. [However, sometimes
> it is far more convenient to implement `sort' than `sortBy'.]
> 
> > sort          =  sortBy (<=)

Just to add a voice to support your assertions, I'd like to mention that
I've already run up against this shortcoming in a balanced tree
implementation that I created.

I would have liked to define a balanced tree as:
data (Ord a) => Tree a = ...

The intention of the balanced tree was to serve as an index for a
collection of variables of a complex data type. To put it in database
terminology, the 'compare' function would compare two records by
examining a small subset of their fields (usually only one field).
Obviously, in such a situation, there are many ways to compare two
records, and thus, many ways to index the same collection of variables.
But alas, the Ord class only allows for one single way of comparing a
data type, so I had to fallback to using the 'sortBy' method.


Reply via email to