Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#979 closed proposal (fixed)

Adding on

Reported by: nad Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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).

The main question seems to be which module to put the function in. Based on previous discussion on the libraries list I suggest creating a new module Control.Function containing on plus (initially) some other combinators (working solely on and with functions) from the Prelude.

Deadline for discussion: 2006-11-09.

Attachments (1)

on.patch (37.5 KB) - added by nad 11 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 11 years ago by nad

Changed the module name to Data.Function.

Changed 11 years ago by nad

Attachment: on.patch added

comment:2 Changed 11 years ago by nad

Resolution: fixed
Status: newclosed

Proposal discussion summary:

  • Consensus was reached that a module containing on plus some functions from the prelude should be added.
  • The module name Control.Function was not well received. A bunch of other names were suggested, and almost everyone accepted Data.Function.
  • It was discussed whether comparing (i.e. on compare) and/or equating (on (==)) should also be present in the libraries. Consensus was reached that either both or none of them should be there, and most people wanted to have them in the libraries. The function comparing is already in the libraries, but not equating. Complaints were raised about the name "equating", though, and no consensus was reached about an alternative name. Hence I leave the comparing/equating discussion open for another proposal.

comment:3 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.