Stack overflow on words (repeat 'a')

View: New views
3 Messages — Rating Filter:   Alert me  

Stack overflow on words (repeat 'a')

by Neil Mitchell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

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.

Thanks

Neil
_______________________________________________
Hugs-Bugs mailing list
Hugs-Bugs@...
http://www.haskell.org/mailman/listinfo/hugs-bugs

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

by Claus Reinke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> 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

_______________________________________________
Hugs-Bugs mailing list
Hugs-Bugs@...
http://www.haskell.org/mailman/listinfo/hugs-bugs

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

by Claus Reinke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i should have mentioned that Prelude.span is less strict, so:

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)

-- Prelude.span fails, span succeeds
test1 span = span (/=' ') $ replicate 1000000 'a' ++ [' ']
test2 span = span (/=' ') $ take 1000000 (cycle "abc") ++ [' ']

-- Prelude.span succeeds, span fails
test3 span = take 1000000 $ fst $ span (/=' ') $ repeat 'a'

claus

_______________________________________________
Hugs-Bugs mailing list
Hugs-Bugs@...
http://www.haskell.org/mailman/listinfo/hugs-bugs