Stack overflow on words (repeat 'a')

Claus Reinke claus.reinke at talk21.com
Tue Jun 26 07:26:20 EDT 2007


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



More information about the Hugs-Bugs mailing list