[Haskell-beginners] Defining custom parser using Parsec

Stephen Tetley stephen.tetley at gmail.com
Tue Oct 19 03:25:57 EDT 2010


On 19 October 2010 03:28, Antoine Latter <aslatter at gmail.com> wrote:

> The cereal[2] library also supports the Alternative operations in the
> Control.Applicative, and is written for decoding low-level binary
> streams, so it presumably also support some form of backtracking. It
> doesn't ship with a "manyTill' function, which is what I would want to
> use for your data, but it doesn't look hard to write. I have no idea
> how well it would perform, though.

Well thought out "serialization" formats shouldn't need a backtracking
parser, as backtracking introduces a substantial performance penalty.

Where binary data formats have alternatives the choice to take is
typically flagged with a tag byte first. I haven't looked much at
recent textual serialization formats like JSON - if they need
backtracking it would be my opinion that they're not very well
designed.

If you want speed for deserializing with a combinator parser avoiding
backtracking choice (i.e. Alternative) is the way to go.


More information about the Beginners mailing list