[Haskell-cafe] Haskell maximum stack depth
ndmitchell at gmail.com
Tue Feb 5 14:05:45 EST 2008
> If you mean an example of coding style and choice of stack vs. heap,
> I already have..
I'm at a loss as why you want a strict version of take. It's clearly
not for performance, as it performs slower. I'd say both the gobbler
programs have a bug, namely that they are not sufficiently lazy.
As an aside, my version of this function would be:
neilGobbler :: Int -> [x] -> [x]
neilGobbler n xs = length res `seq` res
where res = take n xs
I have no idea if it takes the heap or the stack, or if it performs
faster or slower. If you still have whatever test you used on the
gobbler, perhaps you could tell us.
> If you mean an example of it biting with lazy code, this is discussed
> so often you'd be spoiled for choice if you search the mailing list
> archives. Here's a good one..
> This example actually shows the problem twice. In one case it's solvable
> by using foldl' instead of foldl.
Which reduces the memory from O(n) to O(1). Surely thats a good thing,
and the code before had a space leak. Space leak is bad, therefore
telling people about it is good.
I think its sensible to let people set their own stack bound (which is
possible), but that clearly just from taking an informal poll of
respondants to this thread, the current default should indeed be the
default. You seem to be the only person clamouring for an unlimited
stack, and thanks to +RTS, you already have it.
More information about the Haskell-Cafe