[Haskell-cafe] Haskell maximum stack depth

Jonathan Cast jonathanccast at fastmail.fm
Mon Jan 28 21:16:29 EST 2008


On 28 Jan 2008, at 10:07 AM, Neil Mitchell wrote:

> Hi
>
>> ghc uses a pretty conventional stack AFAIK, and it is arbitrarily
>> limited, but you can change the limit with +RTS options.
>
> GHC uses a conventional stack (in that you put stuff at the top, and
> take it off from the top), but it is not a conventional stack in the
> way imperative programs work. In an imperative program if you make a
> function call, a frame gets pushed on the stack. When the function
> call returns, the frame gets popped off the stack. In Haskell, lazy
> evaluation makes it massively more confusing.
>
>> Also, stack "overflows" are a pretty common cause of program failure
>> IME, not at all rare. At least, far more common than whatever error
>> message you get from heap exhaustion (can't even remember the last
>> time I saw one of those).
>
> Yes, I agree. However, in imperative programming stack overflow nearly
> always means you've exceeded some recursion depth in the program, and
> should think about refactoring it to use explicit loops. In Haskell,
> stack overflow is usually a laziness bug. Same error message,
> completely different causes. In Haskell, the solution to stack
> overflow is almost never "increase the stack depth", but "fix your
> laziness leak".
>
> To answer the question if Haskell has a "stack depth restriction ...
> like Java" the answer is no. It has a stack depth restriction, but its
> absolutely nothing like Java in the way it uses the stack, so you
> can't compare them.
>
> My guess is that Istarex's inner thought might have been along the
> lines of "in Java if I do too much recursion I get a stack overflow,
> but Haskell only has recursion, does that mean I get into stack
> overflows all the time?". I could of course be entirely wrong ;-)

Or, to put it another way, the bugs Java's stack overflow is designed  
to catch are considered good style in Haskell.

jcc



More information about the Haskell-Cafe mailing list