I've come to understand functors, applicative functors, and monads as follows:
- Functors: computations that can be mapped over.
- Applicative functors: independent computations whose results can be combined together.
- Monad: (possibly, but not necessarily) dependent computations that can be chained.
However, there is something about Applicative that conflicts with my understanding... Here is a Haskell example of a parser defined on the basis of more basic parsers using the applicative style:
(,) <$> parseName <*> parseEmail
The effects of the two parsers, parseName
and parseEmail
, are not independent, because they both consume tokens from the same input stream, e.g.
Jubobs [email protected]
parseEmail
can only consume what hasn't been consumed by parseName
. How, then, can the two computations be said to be independent?
Monad
, yourparseName
parser cannot make use of the parsed email "returned" byparseEmail
. But of course whatApplicative
is is nothing more than the class and its associated laws. – jberryman