Are applicative functors composed with an applicative style really independent?

I came to understand functors, applicative functors, and monads as follows:

  • Functors: calculations that can be matched.
  • Applicative functors: independent calculations whose results can be combined together.
  • Monad: (possible, but not necessary) dependent calculations that can be bound.

However, there is something about the fact that the Application is contrary to my understanding ... Here is an example of a Haskell parser defined based on simpler parsers using an applicative style:

(,) <$> parseName <*> parseEmail

Effects two parsers parseNameand parseEmailare not independent since they both consume tokens of the same input stream, e.g.

Jubobs jubobs@jubobs.io

parseEmailcan consume only that which has not been consumed parseName. How can we assume that the two calculations are independent?

+4
source share
1 answer

Independence here does not mean that one calculation cannot determine which other calculations were performed, i.e. parseName is not assumed to affect parseEmail. Rather, you cannot use the applicative value (the name analyzed by parseName) to choose which application calculations will be performed as follows: you can analyze only the general email address, and not, say, divulge the email address, verifying that it is not contain the parsed name.

: , "" : , . , , , , .

+16

Source: https://habr.com/ru/post/1662082/


All Articles