[Haskell-cafe] Composing monads

Jules Bean jules at jellybean.co.uk
Fri Nov 23 04:08:24 EST 2007


Maurí­cio wrote:
> Hi,
> 
> If I have two computations a->IO b
> and b->IO c, can I join them to
> get an a->IO c computation? I imagine
> something like a liftM dot operator.

You've already been shown the >=> operator and how to define it from >>= 
by other answers.

Just for variety, here is how you would define it using do notation:

compose :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
compose act act' a = do
   b <- act a
   act' b

Jules




More information about the Haskell-Cafe mailing list