[Haskell-cafe] Haskell on JVM

Maarten Hazewinkel maarten.hazewinkel at gmail.com
Fri Jun 26 09:26:34 EDT 2009

On 26 Jun 2009, at 14:09, Timo B. Hübel wrote:

> And here comes my question: If there is anybody with proper  
> knowledge about
> this issue, I would really like to know what are those things that are
> missing? For example, Clojure lacks proper tail recrusion  
> optimization due to
> some missing functionality in the JVM. But does anybody know the  
> details?

Basically, the JVM lacks a native ability to do tail calls. It does  
not have an
instruction to remove/replace a stack frame without executing an  
actual return
to the calling method/function.

With the heavy use of recursion in functional programs, this is an  
feature in a language implementation to avoid stack overflows.

Some language implementations (Scala) can do partial workarounds by  
the generated code into a loop in the compiler, but this is frequently  
to only deal with self-recursive calls, and does not deal with the  
general case
(X-calls-Y-calls-Z-calls-X...), which a proper implementation of tail- 
calls at
the JVM level would allow.

At the JIT level (below the JVM spec level) some implementations may  
actually do
the tail call optimization anyway, but this is beyond the control of a  
implementation, and would result in a situation where the behaviour of  
program depends on particular implementations/versions/parameters of  
the JVM
running it. That is something to be avoided if possible.

Maarten Hazewinkel
maarten.hazewinkel at gmail.com

More information about the Haskell-Cafe mailing list