Re: Stack overflow on words (repeat 'a')
"Claus Reinke" <[email protected]> Tue, 26 Jun 2007 12:26:20 +0100
| Newsgroups | gmane.comp.lang.haskell.hugs.bugs |
|---|---|
| Message-ID | <007701c7b7e4$d3688f60$780f8351@cr3lt> |
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