[Haskell-cafe] function arithmetic?

Eric Rasmussen ericrasmussen at gmail.com
Sun Sep 1 07:58:34 CEST 2013


Might not be exactly what you're looking for, but Control.Arrow has a rich
set of operators that can be used to combine functions.

For instance, there's an example on
http://en.wikibooks.org/wiki/Haskell/Understanding_arrows showing an addA
function that can be used to apply two functions to the same argument and
add the results:

Prelude> import Control.Arrow
Prelude Control.Arrow> let addA f g = f &&& g >>> arr (\ (y, z) -> y + z)
Prelude Control.Arrow> addA (+2) (*5) 10
62

If you're set on using the + and * operators, I'm guessing it's not
possible to define a (sane) instance of Num for (->), but it would probably
be instructive to try.



On Sat, Aug 31, 2013 at 10:01 PM, Christopher Howard <
christopher.howard at frigidcode.com> wrote:

> Hi. I was just curious about something. In one of my math textbooks I see
> expressions like this
>
> f + g
>
> or
>
> (f + g)(a)
>
> where f and g are functions. What is meant is
>
> f(a) + g(a)
>
> Is there a way in Haskell you can make use of syntax like that (i.e.,
> expressions like f + g and f * g to create a new function), perhaps by
> loading a module or something?
>
> ______________________________**_________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130831/d4f318ef/attachment.htm>


More information about the Haskell-Cafe mailing list