[Haskell-cafe] Mixing Unboxed Mutable Vectors and Parsers

Twan van Laarhoven twanvl at gmail.com
Tue Apr 10 22:48:31 CEST 2012

On 2012-04-07 23:35, Myles C. Maxfield wrote:
> CC: Maintainers of STMonadTrans, Vector, and JuicyPixels
> Hello,
> I am writing a Haskell Attoparsec parser which will modify 2-d arrays
> of small values (Word8, Int8, etc.).
> My first idea was to simply parse all the deltas, and later apply them
> to the input list. However, I can't do that because the value of the
> deltas depend on the value they're modifying.
> My first pass at this program used a function of the form:
> p :: [[Word8]] ->  Parser [[Word8]]
> This approach works, however, the program uses far too much memory.

Does the parser really need the input to determine what to do? Or is the parse 
tree the same regardless? In the latter case, you could perhaps rewrite it to

     p :: Parser ([[Word8]] -> [[Word8]])

or when working with mutable vectors

     p :: MVector s Word8 -> Parser (ST s ())

So instead of explicit deltas, the deltas can just be the function that applies 


More information about the Haskell-Cafe mailing list