[Haskell-cafe] Are there arithmetic composition of functions?
Denis Moskvin
dmoskvin at gmail.com
Tue Mar 20 09:01:26 CET 2012
>
>
> From: Felipe Almeida Lessa <felipe.lessa at gmail.com>
> To: sdiyazg at sjtu.edu.cn
> Cc: haskell-cafe at haskell.org
> Date: Mon, 19 Mar 2012 14:24:13 -0300
> Subject: Re: [Haskell-cafe] Are there arithmetic composition of functions?
> import Control.Applicative
>
> f, g :: Float -> Float
> f x = x + 1
> g x = 2 * x
>
> h = (+) <$> f <*> g
>
>
> Cheers, =)
>
> --
> Felipe.
>
>
Monadic version:
import Control.Monad
import Control.Monad.Instances
(+.) :: Num a => (a -> a) -> (a -> a) -> a -> a
(+.) = liftM2 (+)
(+..) :: Num a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a
(+..) = liftM2 $ liftM2 (+)
infixl 6 +., +..
> (sin +. cos) (pi/4)
1.414213562373095
> ((*) +.. (/)) 4 2
10.0
Deniok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120320/46f005da/attachment.htm>
More information about the Haskell-Cafe
mailing list