Proposal: Adding on
lemming at henning-thielemann.de
Fri Nov 3 06:46:31 EST 2006
On Thu, 2 Nov 2006, Nils Anders Danielsson wrote:
> The function on defined by
> (*) `on` f = \x y -> f x * f y
> is convenient when using functions like sortBy: sortBy (compare `on`
> fst), for example. It also makes the code more readable.
> Furthermore I consider on to be above the Fairbairn threshold, since
> * we get rid of two lambdas,
> * we get rid of the duplication of p,
> * on has some nice algebraic properties (documented in the patch)
> * and, most importantly, it is easier at a glance to understand
> (*) `on` p than to understand \x y -> p x * p y (assuming one knows
> about on).
This reminds me on an earlier discussion:
I expect, that all constructs of a "*By" list function with "on" and
"comparing" are only efficient, if "f" is cheap. That's why I have defined
functions and called them *Key functions, which buffer the results of "f".
I attached the Key suffix in order to show that these functions sort,
group, remove duplicates and so on with respect to a key. I called my "on"
More information about the Libraries