
On Sat, Jan 17, 2004 at 08:24:45AM -0500, ajb@spamcop.net wrote:
Almost all of the times I use the "By" functions follow that pattern: e.g. sortFoos :: [Foo] -> [Foo] sortFoos = sortBy (\x y -> compare (f x) (f y))
Just noting that this particular example has a very simple solution:
http://haskell.org/hawiki/SchwartzianTransform
This technique probably doesn't solve all your problems, though.
It doesn't work when the type Foo doesn't belong to Ord class. There is a simple technique which helped me when I wanted to make a priority queue of elements with Double key, and IO () value. I wanted to use something from Edison, but most of relevant data structures didn't distinguish key from value and insisted that element type belong to Ord class. I just introduced a wrapper type that provides a trivial "Egalite" ordering. newtype NoOrd a = NoOrd { unNoOrd :: a } instance Eq (NoOrd a) where _ == _ = True instance Ord (NoOrd a) where _ `compare` _ = EQ Then I could store in the queue values of type (Double, NoOrd (IO ())) Best regards, Tom -- .signature: Too many levels of symbolic links