
Michael Mossey wrote:
Brandon S. Allbery KF8NH wrote:
Example: in Parsec, "many" is a combinator which takes a parser as an argument and produces a parser that matches multiple successive copies of whatever the argument matches. It doesn't need to know anything about its argument except that it's a parser. This kind of function lets you build up complex but general parsers from smaller pieces.
What makes it a "combinator" and not a general function? The fact that it takes only a function (parser) as input (no data) and produces only a function? Is any function that takes only functions and produces a function called a combinator?
The term "combinator" is just another name for "function", but with a special connotation. It mainly applies to functions building and combining values of an abstract data type. In particular, parsers are abstract. They are defined by the following combinators return :: a -> P a (>>=) :: P a -> (a -> P b) -> P b symbol :: P Char mzero :: P a mplus :: P a -> P a -> P a and an observation function like run :: P a -> String -> Maybe a The above functions are called combinators because they make new parsers from old ones. In contrast, run turns a parser into something else, so it's not called "combinator". Regards, apfelmus -- http://apfelmus.nfshost.com