In monads, Kleisli composition has the type
infix oK: ('b -> 'c monad) -> ('a -> 'b monad) -> ('a -> 'c monad)
and it satisfies the nice algebraic associativity law
(f oK g) oK h = f oK (g oK h)
But in Haskell rather bind
is used:
bind: ('a monad) -> ('a -> 'b monad) -> ('b monad)
whose "associativity" law in not the classic algebraic one:
bind m (λa. bind (k a) (λb. h b)) = bind (bind m (λa. k a)) (λb. h b)
What reasoning led to this choice of favoring bind
over Kleisli composition?
>=>
, it's just not used quite as much as other combinators. I also don't know what "practical" rationale you're expecting. You can always rewritea >>= b ≡ (const a >=> b) ()
anda >=> b ≡ (>>= b) . a
. The closest thing to a 'reason' is that monads were introduced originally to representIO
, and you'd typically want to end onIO ()
nota -> IO ()
, other than that slight convenience the choice is completely arbitrary $\endgroup$>>=
is still just as associative as>=>
, it's just not as easy to see. $\endgroup$