[Haskell-cafe] Composing monads

Brent Yorgey byorgey at gmail.com
Thu Nov 22 16:24:51 EST 2007


On Nov 22, 2007 1:22 PM, Jonathan Cast <jonathanccast at fastmail.fm> wrote:

> On 22 Nov 2007, at 10:17 AM, 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.
>
> This is called Kleisli composition, by the way; it's defined as (>=>)
> in Control.Monad.
>
> jcc
>
>
Even if you didn't know about (>=>)  (I didn't, actually!), it's not too
hard to write yourself:

(>=>) :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)
(>=>) f g a = f a >>= g

There's no magic, just follow the types. =)

-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071122/8b795dd8/attachment.htm


More information about the Haskell-Cafe mailing list