Applicative
's has the (<*>)
function:
(<*>) :: (Applicative f) => f (a -> b) -> f a -> f b
Learn You a Haskell shows the following function.
Given:
ap :: (Monad m) => m (a -> b) -> m a -> m b
ap f m = do
g <- f -- '<-' extracts f's (a -> b) from m (a -> b)
m2 <- m -- '<-' extracts a from m a
return (g m2) -- g m2 has type `b` and return makes it a Monad
How could ap
be written with bind
alone, i.e. >>=
?
I'm not sure how to extract the (a -> b)
from m (a -> b)
. Perhaps once I understand how <-
works in do notation
, I'll understand the answer to my above question.