From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA13158 for caml-red; Thu, 8 Feb 2001 20:08:06 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA00895 for ; Thu, 8 Feb 2001 20:04:06 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f18J45X10114 for ; Thu, 8 Feb 2001 20:04:05 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA06636 for caml-list@inria.fr; Thu, 8 Feb 2001 20:04:05 +0100 (MET) Resent-Message-Id: <200102081904.UAA06636@pauillac.inria.fr> Date: Thu, 8 Feb 2001 20:03:30 +0100 From: Xavier Leroy To: Don Syme Subject: Re: OCaml on CLR/JVM? Message-ID: <20010208200330.A10340@pauillac.inria.fr> References: <0C682B70CE37BC4EADED9D375809768A02DB1D6E@red-msg-04.redmond.corp.microsoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <0C682B70CE37BC4EADED9D375809768A02DB1D6E@red-msg-04.redmond.corp.microsoft.com>; from dsyme@microsoft.com on Mon, Feb 05, 2001 at 04:03:12PM -0800 Resent-From: Xavier.Leroy@inria.fr Resent-Date: Thu, 8 Feb 2001 20:04:05 +0100 Resent-To: caml-list@inria.fr Sender: weis@pauillac.inria.fr > Now I have to say the obvious: wouldn't it be wonderful if Caml interfaced > with either Java or the .NET Common Language Runtime seemlessly so we > wouldn't have to keep facing these kinds of questions and problems, and > could just leverage existing libraries? I've been working on and off (mostly off, lately) on an OCaml/Java interface that works by coupling the two systems at the C level via their foreign-function interfaces (Java's JNI and OCaml's C interface). This was strongly inspired by the work of Erik Meijer et al on a similar Haskell/Java interface. (These Haskell guys sure are at the bleeding edge of language interoperability. This is the second interop idea I steal from them, after the IDL/COM binding.) The low-level coupling is surprisingly easy, including making the two garbage collectors cooperate: both the JNI and OCaml's C interface provide enough functionality to get the couping to work without *any* modification on either of the implementations. How nice! The only limitation is that a cross-heap cycle (a Java object pointing to a Caml block pointing back to the Java object) can never be reclaimed... (Thanks to Martin Odersky for pointing this out.) (Actually, the main problem is working around the bugs in Sun's JDK 1.2.2 for Linux. These guys must be kidding. Does anyone has a recommendation for a solid, complete Java implementation (including Java 2 and of course the JNI) for Linux?) Of course, the low-level interface is type-unsafe, so the real fun is to build a type-safe view of Java classes and objects as Caml classes and objects, and conversely. I'm still struggling with some of the issues involved. For instance, it turns out to be much simpler (for the implementation, not for the final user!) to map Java objects to values of abstract Caml types, and treat methods as functions over these abstract types, than mapping Java objects to Caml objects. That was quite unexpected! One thing I learnt is that the real problem with language interoperability is not how to compile language X to virtual machine Y (this can always be done, albeit more or less efficiently), but rather how to map between X's data structures and objects and those of all other languages Z1 ... Zn that also compile down to Y. This is obvious in retrospect, but I think many (myself included) often overlook this point and believe that compiling to the same virtual machine is necessary and sufficient for interoperability. It is actually neither necessary nor sufficient... While this work started with the JVM, I'm pretty sure it can be made to work with the .NET CLR, as soon as it will have a foreign-function interface with features comparable to those of the JNI. (And I'm sure this will happen eventually, not only because it makes sense, but also because Java has it, so .NET must too :-) Stay tuned for further developments. - Xavier Leroy