[Haskell] simple function: stack overflow in hugs vs none in ghc
John Lask wrote: : | The following code causes a "C stack overflow" in hugs (version 20051031) | but not in ghc (version 6.6) | The point of the exercise is to process a very large file lazily, | returning the consumed and unconsumed parts (i.e. basic parser combinators). : | > sqnc p ts = let ( r, ts' ) = p ts in case r of | > Nothing -> ([],ts') | > Just x -> let (r',ts'') = (sqnc p ts') in (x:r', ts'' ) : I don't know how ghc is avoiding the stack overflow, but it looks like it's caused by strict pattern matching. The first call to sqnc wants reassurance that the second call is returning a pair (as opposed to _|_) before deciding that it's OK to return a pair. Try putting a tilde in the recursive call, to make the pattern lazy. let ~(r',ts'') = ... There's a recent thread on lazy patterns in the haskell-cafe list, too. http://www.haskell.org//pipermail/haskell-cafe/2007-September/031974.html Regards, Tom ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
[Haskell] simple function: stack overflow in hugs vs none in ghc
Hi hoping someone can shed some light on this: The following code causes a "C stack overflow" in hugs (version 20051031) but not in ghc (version 6.6) The point of the exercise is to process a very large file lazily, returning the consumed and unconsumed parts (i.e. basic parser combinators). The simplified (stylised example of the problem) is displayed bellow. test1 (on a large file) will succeed in ghc but fail in hugs test2 on same file will succeed in both ghc and hugs the problem appears to be retaining a hold on the unconsummed portion and returning it. maybe something to do with updating CAFS, all too subtle for me. The question: is there any changes that can be made to the code to make test1 work in hugs without changing the essence of the function. test1 = readFile "big.dat" >>= (\x->print $ parse x) test2 = readFile "big.dat" >>= (\x->print $ fst $ parse x) big.dat is just some large data file say 1MB. (not particularly large by todays standards!) parse x = sqnc item x where item =( \ ts -> case ts of [] -> ( Nothing, []) ts -> ( Just (head ts), tail ts) ) sqnc p ts = let ( r, ts' ) = p ts in case r of Nothing -> ([],ts') Just x -> let (r',ts'') = (sqnc p ts') in ( x:r', ts'' ) _ Advertisement: Search for local singles online at Lavalife http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D30290&_t=764581033&_r=email_taglines_Search&_m=EXT ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell