GHC: Ticket #979: Adding on
http://ghc.haskell.org/trac/ghc/ticket/979
<p>
The function <tt>on</tt> defined by
</p>
<pre class="wiki">(*) `on` f = \x y -> f x * f y
</pre><p>
is convenient when using functions like <tt>sortBy</tt>: <tt>sortBy (compare `on` fst)</tt>, for example. It also makes the code more readable.
</p>
<p>
Furthermore I consider <tt>on</tt> to be above the Fairbairn threshold,
since
</p>
<ul><li>we get rid of two lambdas,
</li><li>we get rid of the duplication of p,
</li><li><tt>on</tt> has some nice algebraic properties (documented in the
patch)
</li><li>and, most importantly, it is easier at a glance to understand <tt>(*) `on` p</tt> than to understand <tt>\x y -> p x * p y</tt> (assuming one knows about <tt>on</tt>).
</li></ul><p>
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 <tt>Control.Function</tt> containing <tt>on</tt> plus (initially) some other combinators (working solely on and with functions) from the Prelude.
</p>
<p>
Deadline for discussion: 2006-11-09.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/979
Trac 1.0.1nadFri, 03 Nov 2006 12:43:14 GMT
http://ghc.haskell.org/trac/ghc/ticket/979#comment:1
http://ghc.haskell.org/trac/ghc/ticket/979#comment:1
<p>
Changed the module name to <tt>Data.Function</tt>.
</p>
TicketnadFri, 10 Nov 2006 12:27:26 GMTattachment set
http://ghc.haskell.org/trac/ghc/ticket/979
http://ghc.haskell.org/trac/ghc/ticket/979
<ul>
<li><strong>attachment</strong>
set to <em>on.patch</em>
</li>
</ul>
TicketnadFri, 10 Nov 2006 12:28:27 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/979#comment:2
http://ghc.haskell.org/trac/ghc/ticket/979#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
Proposal discussion summary:
</p>
<ul><li>Consensus was reached that a module containing <tt>on</tt> plus some functions from the prelude should be added.
</li></ul><ul><li>The module name <tt>Control.Function</tt> was not well received. A bunch of other names were suggested, and almost everyone accepted <tt>Data.Function</tt>.
</li></ul><ul><li>It was discussed whether <tt>comparing</tt> (i.e. <tt>on compare</tt>) and/or <tt>equating</tt> (<tt>on (==)</tt>) 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 <tt>comparing</tt> is already in the libraries, but not <tt>equating</tt>. Complaints were raised about the name "<tt>equating</tt>", though, and no consensus was reached about an alternative name. Hence I leave the <tt>comparing</tt>/<tt>equating</tt> discussion open for another proposal.
</li></ul>
TicketsimonmarTue, 30 Sep 2008 15:40:04 GMTarchitecture changed
http://ghc.haskell.org/trac/ghc/ticket/979#comment:3
http://ghc.haskell.org/trac/ghc/ticket/979#comment:3
<ul>
<li><strong>architecture</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketsimonmarTue, 30 Sep 2008 15:51:09 GMTos changed
http://ghc.haskell.org/trac/ghc/ticket/979#comment:4
http://ghc.haskell.org/trac/ghc/ticket/979#comment:4
<ul>
<li><strong>os</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
Ticket