This excellent answer in this question demonstrates how bind
can be written in terms of join
and fmap
:
(>>=) :: m v -> (v -> m w) -> m w
says "if you have a strategy to produce a v, and for each v a follow-on strategy to produce a w, then you have a strategy to produce a w". How can we capture that in terms of join?
mv >>= v2mw = join (fmap v2mw mv)
But, I don't understand how v2mw
, which has a type of a -> m b
type checks to the first argument of fmap
.
fmap :: Functor f => (a -> b) -> f a -> f b