vlasovskikh / funcparserlib

Recursive descent parsing library for Python based on functional combinators
https://funcparserlib.pirx.ru
MIT License
338 stars 38 forks source link

In the Tutorial, don't use "composition" to refer to fmapping a function with a parser #39

Closed rgleichman closed 2 years ago

rgleichman commented 9 years ago

From the tutorial:

See how composition works. We compose a parser some(...) of type Parser(Token, Token) with the function tokval and we get a value of type Parser again, but this time it is Parser(Token, str). Let's put it this way: the set of parsers is closed under the application of >> to a parser and a function of type a -> b.

As a functional programmer, this is confusing since this is an instance of fmapping, not function composition. Also, the tutorial also uses "composition" to refer to composing two parsers

We should be careful and compose parsers using | so that they don't conflict with each other:

To me, the first quote would make more sense if it read:

See how fmapping works. We fmap the function tokval with a parser some(...) of type Parser(Token, Token) and we get a value of type Parser again, but this time it is Parser(Token, str). Let's put it this way: the set of parsers is closed under the application of >> to a parser and a function of type a -> b.

Of course, if someone does not know about functors, this might be confusing.

vlasovskikh commented 9 years ago

Yes, "composition" should be used for function composition only in this document. The word "combination" might be more appropriate here. I was referencing "Primitives, Combination, and Abstraction" section from the SICP course. But for some reason I got "combination" mixed with "composition". Would this sound better to you:

See how combination works. We combine a parser some(...) of type Parser(Token, Token) with the function tokval and we get a value of type Parser again, but this time it is Parser(Token, str). Let's put it this way: the set of parsers is closed under the application of >> to a parser and a function of type a -> b.

We should be careful and combine parsers using | so that they don't conflict with each other:

rgleichman commented 9 years ago

Yes, that sounds better. The rshift docstring talks about "transforming", so that also might be good language to use.

vlasovskikh commented 3 years ago

I've replaced the term "composition" with "combination" from the API docs and docstrings. I intend to update the tutorial as well.

vlasovskikh commented 2 years ago

Fixed for the new Getting Started guide.