[Haskell] simple function: stack overflow in hugs vs none in ghc

john lask jvlask at hotmail.com
Thu Sep 20 18:30:11 EDT 2007


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 

More information about the Haskell mailing list