For MLj the answers so far as I remember are:
[EMAIL PROTECTED] wrote:
>
> To those of you who are working on implementations:
> How do you implement
>
> 1) tail recursion
You can only do so much. The Java VM has a goto instruction but you
can't jump from one virtual method to another. Things that get called only
once from outside get inlined, so you end up with procedures which have
quite a reasonably large size and a lot of the tail recursions will turn
into GOTOs. But for example if you have two functions
fun a x =
let
(do some stuff)
in
b (args)
fun b y = (same as b except it tailrecurses to a)
which both are called externally, then you have to have separate methods.
(Unless you either (a) copy code or (b) have one method representing two
methods, with a header which works out which of a and b to jump to. Which
MLj doesn't do.)
> 2) polymorphism
Expanded out everywhere.
> 3) closures & eval (i.e., laziness)
ML is of course strict, so MLj doesn't have to do strictness analysis.
Closures are represented in the obvious way by virtual methods, though there's
a lot of cleverness used to compact the representation a bit so you don't
end up with 5000 classes.
If the JVM has got any further with implementing "immutable" classes
(see the Gosling report on Numerical extensions to Java) then this could be
a big help for compiler writers from functional languages. An immutable
class object is basically one which, once initialised, is guaranteed to
have a complete set of unchangable fields. Then the JVM can do all sorts
of optimisations. Immutable classes were demanded for complex numbers, but
correspond to almost everything for functional languages.