[Haskell-cafe] Impact of "try" on Parsec performance

Omari Norman omari at smileystation.com
Sat Mar 3 05:30:22 CET 2012


The Parsec documentation says that Parsec performs best on predictive
grammars, and Parsec does not backtrack by default to improve performance
(though this also improves error messages).

On the other hand, I notice that attoparsec and polyparse backtrack by
default, and attoparsec claims to be faster than Parsec (I can't remember
if polyparse makes this claim).

The Parsec documentation says there is a penalty for using try and suggests
left-factoring grammars when possible. Real World Haskell says that
excessive use of try can degrade Parsec performance quite significantly. On
the other hand, some of the combinators provided with Parsec, such as
notFollowedBy, use try.

So my question is: what is the practical impact of using try? I ask because
as a novice I have a simple grammar that could, perhaps, be factored to
avoid use of try, but it's quite a brain puzzle for me and I wonder if it
would ever be worth it. Does it matter how many characters "try" would have
to store, or how often it would run?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120302/b3d75cb6/attachment.htm>


More information about the Haskell-Cafe mailing list