Speaking of small functions

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Oct 29 10:19:10 EST 2006


On Sun, 2006-10-29 at 14:46 +0000, Jon Fairbairn wrote:
> On 2006-10-29 at 09:30EST kahl at cas.mcmaster.ca  wrote:
> >  > 
> >  > Speaking of small functions, Kleisli composition should at least be in
> >  > Control.Monad. It's a simple thing, and not commonly explicitly used
> >  > at the moment, but rather important conceptually.
> >  > 
> >  > (@@) :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)
> >  > g @@ f = \x -> f x >>= g
> > 
> > I support this strongly.
> > 
> > My notation is (=>>=), to go with (>>=).
> 
> That's a better symbol for it. (@@) could be just about
> anything, while (=>>=) is suggestive. Though I think what it
> suggests might be with the arguments in a different order?

Yes, we already have =<< for reverse >>= which is nice sometimes when
you want to emphasise the similarity to (.) rather than imperative
order, eg:

return . foldr h z . map f . filter p =<< getContents


So it'd be:

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

(or should it really be written with a lambda?)

and if there's demand for (=>>=) too then that's obviously easy to add.

Duncan



More information about the Libraries mailing list