[Haskell-cafe] Either Monad and Laziness

timothyhobbs at seznam.cz timothyhobbs at seznam.cz
Tue Sep 11 21:51:53 CEST 2012


Use a tuple: (Result,Maybe Error) rather than an Either.  Do everything 
lazily, and in the case of an error, undo the result.


---------- Původní zpráva ----------
Od: Eric Velten de Melo <ericvmelo at gmail.com>
Datum: 11. 9. 2012
Předmět: [Haskell-cafe] Either Monad and Laziness
"Hello,

I am currently trying to rewrite the Graphics.Pgm library from hackage
to parse the PGM to a lazy array. The current implementation parses it
straight to UArray, which is strict.

The behaviour I want to achieve is like this: I want the program when
compiled to read from a file, parsing the PGM and at the same time
apply transformations to the entries as they are read and write them
back to another PGM file.

The problem is that even using a lazy array structure, because the
parser returns an Either structure it is only possible to know if the
parser was successful or not after the whole file is read, therefore
requiring it to read the entire file before applying the
transformations, ruining the property of laziness.

Is there some way to keep this from happening? Should I even want to
make it like this? Not really a real life situation, but imagine I
want to read a reaaaaally large PGM file which does not fit into RAM
memory and I don't want to be forced to have the whole array in the
memory at once.

One alternative I thought was parsing only the PGM header and then
read the rest of the input without using Parsec and the Either Monad.
In the event the data is corrupted, though, I would not know how to
recover from it.

Any thoughts? Hopefully I'm not saying anything really stupid.

Eric

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
(http://www.haskell.org/mailman/listinfo/haskell-cafe)"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120911/f7c6c4c6/attachment.htm>


More information about the Haskell-Cafe mailing list