[Haskell-cafe] Laziness through boxing
C Rodrigues
red5_2 at hotmail.com
Tue Jan 16 16:05:15 EST 2007
I had a problem with strictness in the Parsec library, and I'd like to know
if there's a good way to solve it. The following illustrates the problem.
This raises an error when run:
main = parseTest (return undefined >> return 0) ""
Whereas this does not:
main = parseTest (return (Just undefined) >> return 0) ""
I have a parser that does parsing and name resolution at the same time, by
passing the completed symbol table in as a part of the parser state.
Lookups into the completed symbol table have to be lazy since that symbol
table is not ready until parsing is complete. My parser kept producing
<<loop>> when it ran, which turned out to be an effect of strictness in
Parsec.
My solution was to box all the lazy values with Just. The result feels
awkward to me. It involves fromJust, and moreover, it's easy to miss a
place where boxing is required, and hard to track down the cause of a
<<loop>>. Is there a better way to deal with this issue? And why is Parsec
strict in return values?
-Chris
_________________________________________________________________
>From photos to predictions, The MSN Entertainment Guide to Golden Globes has
it all. http://tv.msn.com/tv/globes2007/?icid=nctagline1
More information about the Haskell-Cafe
mailing list