Stack overflow on words (repeat 'a')

Claus Reinke claus.reinke at
Tue Jun 26 06:47:44 EDT 2007

> With the expression: words (repeat 'a')
> Using WinHugs Sep 06 I get a stack overflow.
> Using Hugs Linux May 06 I get a GC fails to reclaim sufficient space error
> Using GHC and Yhc both of these succeed.
> I have a similar issue in one of my functions which is showing the
> same behaviour.

assuming you've got a terminating application in mind,-) a slightly 
more interesting expression is:

    test span = span (/=' ') $ replicate 100000 'a' ++ [' ']

without optimizations, hugs is prone to fail for such deep applications
of non-tail-recursive functions like span/break, splitAt, ..

try this variation:

span p l = span' p l id
  span' p []     = \c->c ([],[])
  span' p xs@(x:xs') 
     | p x       = span' p xs' . (\c (a,b)->c (x:a,b))
     | otherwise = \c->c ([],xs)


More information about the Hugs-Bugs mailing list