[Haskell-cafe] Mixing Unboxed Mutable Vectors and Parsers

Stephen Tetley stephen.tetley at gmail.com
Sun Apr 8 21:05:34 CEST 2012

On 8 April 2012 19:17, Myles C. Maxfield <myles.maxfield at gmail.com> wrote:
> It's a JPEG parser.

Ahem, I'm a bit of of my depth then, but one thing you should consider
is that writing your own parser monad is trivial, especially for well
defined binary formats. Well defined binary formats should be
deterministic and don't need backtracking, hence you won't need to
worry about defining Alternative / MonadPlus instances which is where
the complication lies.

As you should be able to live without backtracking for JPEG it
shouldn't be hard to make the parser efficient if you stick closely to
the API of the Vector or Array library you are using - e.g. you might
want to move a cursor forward through the Array rather than
"unconsing" [*] at the head which would create work for the garbage
collector. This should still be amenable to streaming - you just work
at a larger chunk size.

Presumably you've seen Jeroen Fokker's paper on JPEG decoding with
Gofer? (Gofer is ~= Haskell).

[*] Parsec etc. work by unconsing the head of the input stream.

More information about the Haskell-Cafe mailing list