Re: [Haskell-cafe] Are there arithmetic composition of functions?

20 Mar
2012
20 Mar
'12
4:01 a.m.
From: Felipe Almeida Lessa
To: sdiyazg@sjtu.edu.cn Cc: haskell-cafe@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
4810
Age (days ago)
4810
Last active (days ago)
0 comments
1 participants
participants (1)
-
Denis Moskvin