This general applicative pattern for numbers is packed up in the applicative-numbers package [1].<br><br>In addition to Ralf&#39;s paper, there&#39;s a discussion in section 10 of *Denotational design with type class morphisms* [2] and an application in sections 2 &amp; 4 of *Beautiful differentiation* [3].<br>

<br>[1]: <a href="http://hackage.haskell.org/package/applicative-numbers">http://hackage.haskell.org/package/applicative-numbers</a><br>[2]: <a href="http://conal.net/papers/type-class-morphisms/">http://conal.net/papers/type-class-morphisms/</a><br>

[3]: <a href="http://conal.net/papers/beautiful-differentiation/">http://conal.net/papers/beautiful-differentiation/</a><br><br>-- Conal<br><br><div class="gmail_quote">On Mon, Mar 19, 2012 at 9:58 PM, wren ng thornton <span dir="ltr">&lt;<a href="mailto:wren@freegeek.org">wren@freegeek.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 3/19/12 12:57 PM, <a href="mailto:sdiyazg@sjtu.edu.cn" target="_blank">sdiyazg@sjtu.edu.cn</a> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
By arithmetic I mean the everyday arithmetic operations used in engineering.<br>
In signal processing for example, we write a lot of expressions like f(t)=g(t)+h(t)+g&#39;(t) or f(t)=g(t)*h(t).<br>
I feel it would be very natural to have in haskell something like<br>
</blockquote>
<br></div>
You should take a look at Ralf Hinze&#39;s _The Lifting Lemma_:<br>
<br>
    <a href="http://www.cs.ox.ac.uk/ralf.hinze/WG2.8/26/slides/ralf.pdf" target="_blank">http://www.cs.ox.ac.uk/ralf.<u></u>hinze/WG2.8/26/slides/ralf.pdf</a><br>
<br>
The fact that you can lift arithmetic to work on functions comes from the fact that for every type T, the type (T-&gt;) is a monad and therefore is an applicative functor. The output type of the function doesn&#39;t matter, except inasmuch as the arithmetic operations themselves care.<br>


<br>
<br>
This pattern has been observed repeatedly, even long before Haskell was around. But one reason it&#39;s not too common in production Haskell code is that it&#39;s all too easy to make a mistake when programming (e.g., you don&#39;t mean to be adding functions but you accidentally forget some argument), and if you&#39;re using this trick implicitly by providing a Num instance, then you can get arcane/unexpected/unhelpful error messages during type checking.<br>


<br>
But then you do get some fun line noise :)<br>
<br>
    twiceTheSumOf  = (+) + (+)<br>
    squareTheSumOf = (+) * (+)<br>
    cubeTheSumOf   = (+) * (+) * (+)<br>
<br>
    -- N.B., the names only make sense if all arguments<br>
    -- are numeric literals. Don&#39;t look at the types.<br>
    addThreeThings = (+) . (+)<br>
    addFourThings  = (+) . (+) . (+)<br>
    addFiveThings  = (+) . (+) . (+) . (+)<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Live well,<br>
~wren</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>