> Le 09/03/2012 18:12, Philippe Veber a écrit :
>> Dear camlers,
>> I used js_of_ocaml several times and was really stunned of how clever
>> (notably because writing interfaces boils down to writing types) and
>> efficient this approach is. Would a similar thing work for the JVM, that
>> is a compiler from ocaml bytecode to java bytecode?
It is not easy to envision such a tool on the JVM, because of the current
restrictions imposed on Java bytecode. As an example, the size of a method
is currently limited to 64Ko, which is clearly way too small for non trivial
>> I guess it wouldn't
>> provide a full interoperability with java, in the sense that creating or
>> extending classes may not be possible (well, why not after all?).
>> However, being able to run an ocaml program on the JVM reusing existing
>> java libraries would be so useful already!
I am currently working on this for OCaml-Java (see below).
>> Are there known obstacles to this? Has anyone tried something in this
Well, no real obstacle as OCaml-Java showed.
However, OCaml-Java 1.x is still a bare proof of concept due to both
poor design choices and JVM limitations. But then came Java 1.7 and
some limitations were removed (e. g. a garbage collector better suited
to functional languages, and an implementation of method handles).
OCaml-Java has been largely rewritten and now exhibit acceptable
>> Would there be a chance to support multicore programming that
Yes, it is actually working. But not released yet.
Starting from vanilla OCaml, you "only" need two things:
1/ have a reentrant runtime;
2/ have a parallel garbage collector.
OCaml-Java implements the former, while all modern JVMs provide the latter.
So, basically, it just works. The great difficulty is then to provide the good
abstractions to make the life of the programmer as easy as possible.
I mean: who would like to program with locks?
Thanks for the plug. However, OCaml-Java is quite different and provides two tools:
- an equivalent of ocamlrun written in Java (meaning you can interpret
OCaml bytecode inside a JVM);
- an equivalent of ocamlc/ocamlopt for Java (meaning you can compile
OCaml sources to Java jar files to be executed by a JVM).