[Haskell-cafe] RE: simple function: stack overflow in hugs
vsnonein ghc
Claus Reinke
claus.reinke at talk21.com
Mon Sep 24 11:20:42 EDT 2007
> afraid not
>
> the given example is too strict, the requirement is to generate the matched
> portion lazilly, and return the tail (unconsumed portion).
ah yes, without optimisations, Prelude.span builds up stack,
while the continuation-based alternative i mentioned is too
strict for some uses.
> In principle the function should be capable of being written to run in
> constant space which the given example dose not.
>>>return (repeat 'a') >>= \ x -> print $ span (const True) x
how about the old spec, then?
span p l = (takeWhile p l,dropWhile p l)
since takeWhile takes forever, here, it isn't even inefficient!-)
claus
>>>with hugs you will get a stack error, in ghc it executes in constant
>>>space, i.e. indefinitely. In essenece the above example does exactly the
>>>same as my ealier code.
>>
>>this thread might be relevant:
>>
>>http://www.haskell.org/pipermail/hugs-bugs/2007-June/001815.html
>>http://www.haskell.org/pipermail/hugs-bugs/2007-June/001816.html
>>http://www.haskell.org/pipermail/hugs-bugs/2007-June/001817.html
More information about the Haskell-Cafe
mailing list