[<<][meta][>>][..]

Sat Jul 16 10:53:12 CEST 2011

## Type of bind

The next question that pops to mind is: why doesn't bind have the
following type?
(a -> Mb) -> (b -> Mc) -> (a -> Mc)
The reason is that here we _fix the input_ of each computation.
I.e. this would work fine for simple pipes, but there is no room
"cross product". I.e. in this type the computation (b -> Mc) is
independent of a.
What would make sense is this:
Ma -> Mb -> (a -> b -> Mc) -> Mc
which using currying of the (a -> b -> Mc) operation can be written as
2 applications of bind.
Moral of the story: bind doesn't care where the first arrow comes
from, only that the end of the first arrow is compatible with the
start of the next.
But in some cases one does want to just chang multiple (a -> M b)
together. How to do that?
composeM :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)
composeM f g x = f x >>= g
Ok, found it: called "left-to-right Kleisli composition" in [1] and is
denoted by (>=>).
[1] http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html

[Reply][About]

[<<][meta][>>][..]