Re: Stack overflow on words (repeat 'a')

"Claus Reinke" <[email protected]> Tue, 26 Jun 2007 11:47:44 +0100
Newsgroups gmane.comp.lang.haskell.hugs.bugs
Message-ID <006601c7b7df$6e717db0$780f8351@cr3lt>
> 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
  where
  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)

claus