[Haskell-cafe] Parsec combinator like Prolog's cut operator?

Antoine Latter aslatter at gmail.com
Wed Jun 30 00:33:10 EDT 2010


On Tue, Jun 29, 2010 at 10:26 PM, Erik de Castro Lopo
<mle+hs at mega-nerd.com> wrote:
> Hi all,
>
> I'm reading John Hughes' paper "Generalizing Monads to Arrows" and found
> the statement regarding parser combinators:
>
>   "... depend on the programmer using an additional combinator similar
>   to Prolog's 'cut' operator do declare that a parser need never
>   backtrack beyond a certain point."
>
> Does something like this already exist in Parsec? If not is there a way
> to write it?
>
> Having this would really help with a parsing problem I have.
>
> Cheers,
> Erik

For Parsec, in the absence of the "try" combinator, a parser will
never back-track once it consumes a portion of the input.

If "try" is pushed out into the leaves of you parser, you shouldn't
run in to too much trouble with excessive backtracking.

What problems are you running in to?

Take care,
Antoine


More information about the Haskell-Cafe mailing list