[Haskell-cafe] multiple computations, same input

Josef Svenningsson josef.svenningsson at gmail.com
Mon Mar 27 20:13:23 EST 2006

On 3/28/06, Neil Mitchell <ndmitchell at gmail.com> wrote:
> > This feels like a situation Parsec users would find themselves in all the
> > time.  When you have a bunch of parsers in a 'choice', does the start of the
> > input stream linger until the last parser is executed?
> No, as soon as one token is accepted from any parser, that input is
> decided upon, and it will never go back. If you want that behaviour
> you have to wrap the particular parser in try, which does give the
> backtracking (and space leak)
I personally find this behaviour terribly confusing. It makes writing
the parser highly unmodular. It forces me to know exactly what a
certain parser recognizes to know whether I need to wrap a 'try'
around it when I compose it in parallel with another parser. Which is
why I much prefer to use parsing libraries based on Koen Claessen's
technique which performs all parses at the same time. It works
breadth-first on the parse forest (the set of parse trees).
Text.ParserCombinators.ReadP is one example which uses this technique.



More information about the Haskell-Cafe mailing list