Johannes Waldmann wrote:
>
> Wouldn't it be nice if there were a Haskell compiler backend
> that produced Java bytecode? Then I could write applets
> in my favourite language, compile them, put them on my web page,
> and everyone could execute them in their browser...
>
> Seriously, is there any work in that direction?
> Surely someone must have investigated this before.
> Perhaps there are convincing arguments why it can't/shouldn't be done?
Nick Benton, Andrew Kennedy and I collaborated on a compiler from
Standard ML to Java bytecode. I at least am no longer working on this
(our employer folded), but Andrew is (for Microsoft Research!), see
http://www.dcs.ed.ac.uk/home/mlj/
and
http://research.microsoft.com/~akenn/
If there were an easy way of interfacing Glasgow Haskell to
SML you could try getting GHC to output MLj's Monadic Intermediate
Language, then you would be saved a lot of the work of optimisation.
(However, I doubt if MLj does as much purity analysis as Haskell,
as for ML it's not such a profitable tactic.)
A highlight is that for MLj all polymorphism is expanded out.
This is pretty important for Java, since otherwise all integers etcetera
would have to be Objects. The Object overhead in Java can be pretty
considerable. Expanding polymorphism also simplifies the compiler.
On the other hand, it costs quite a lot of CPU time; last I heard
Andrew was able to get MLj to compile itself, but it still takes quite
a while.
If I were starting over again I would look at the work Laurie
J. Hendren's group is doing, see
http://www-acaps.cs.mcgill.ca/~hendren/
Finally, I should note that one of our biggest problems was being
a hostage to the mistakes of the various JVMs out there. (For example
Microsoft's was often the fastest but we kept having to insert hacks
to work around Microsoft bugs & so on & so on.)