List functions - "Under" operations

Tomasz Zielonka t.zielonka at
Fri Jan 16 11:03:21 EST 2004

On Fri, Jan 16, 2004 at 01:43:40AM -0800, Brandon Michael Moore wrote:
> Hello, and welcome me to the list

Welcome to the list! :)

> I think it would often be useful if the list functions with class
> constraints had versions paramaterized on a function mapping your element
> type into an instance of the classes, in addition to the "By" forms that
> take an implementation for the required class method.
> 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))

No need for so many new functions. Just write a function:

  composeFGxGy :: (b -> b -> c) -> (a -> b) -> a -> a -> c
  composeFGxGy f g x y = f (g x) (g y)

Then you can:

  sortFoos = sortBy (composeFGxGy compare f)

> How does this sound?

And how does _this_ sound? ;)

Best regards,

.signature: Too many levels of symbolic links

More information about the Libraries mailing list