[Haskell-cafe] Haskell maximum stack depth

Adrian Hey ahey at iee.org
Mon Jan 28 12:45:50 EST 2008


Neil Mitchell wrote:
> Hi Istarex,
> 
>> Does Haskell have a maximum stack depth restriction like Java &
>> Python, or is it only limited by the maximum stack available on the
>> system (i.e. what would be available to a C program)?
> 
> You are probably thinking that recursive functions use up program
> stack, and hence the stack depth bounds the amount of recursion. In
> Haskell, that isn't the case. Haskell is lazily evaluated, and has
> tail recursion, which means that you rarely run into a problem with
> exceeding the stack depth. In GHC the "stack" is stored in the heap
> area of memory, so is not limited to the C stack, but can be set at
> runtime with a flag (+RTS ... something ...) - but you won't need to.

Sorry, but I think that's a very misleading answer to give to someone
(who's presumably a noob).

The answer is that no such limit is defined in the standard, for the
obvious reason that the standard does not presume anything about
runtime implementation, not even the presence of a "stack".

ghc uses a pretty conventional stack AFAIK, and it is arbitrarily
limited, but you can change the limit with +RTS options.

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).

Regards
-- 
Adrian Hey


More information about the Haskell-Cafe mailing list