> > > From: Felipe Almeida Lessa <felipe.le...@gmail.com> > To: sdiy...@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
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe