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 jubobs@jubobs.io
parseEmail
can only consume what hasn't been consumed by parseName
. How, then, can the two computations be said to be independent?