Laziness through boxing

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

C Rodrigues wrote:
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
To get better unboxing you can make your own box: data Box a = Box {unBox :: a} and then replace fromJust with unBox
participants (2)
-
C Rodrigues
-
Chris Kuklewicz