caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: "Ulf Wiger (TN/EAB)" <ulf.wiger@ericsson.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocaml dll in an Erlang runtime
Date: Fri, 22 Jun 2007 10:02:56 +0200	[thread overview]
Message-ID: <467B8230.9090904@inria.fr> (raw)
In-Reply-To: <6616D98C65DD514BA2E1DDC5F92231550228B6EB@esealmw115.eemea.ericsson.se>

> Would any of you be interested in prototyping a semi-tight coupling
> between Erlang and OCaml? [...] Do you think it's doable?

I haven't looked closely at the Erlang interop facilities, but I think
it is doable.  Here are some remarks based on previous
interoperability experiences with Caml.

The first step is to find a good mapping between data structures of
the two languages.  When both are statically typed, this can be
difficult as both type systems try to impose their views.
When at least one of the languages is dynamically typed, it's easier.

One approach is to define a Caml datatype that reflects the
"universal" type of the dynamically-typed language, e.g. S-exprs in
the case of Lisp, and provide low-level interface functions to
exchange values of this type.

Conversions between this Caml representation of the universal type and
regular Caml data structures can be written manually in Caml, or maybe
automatically generated in the style of Markus Mottl's Sexplib tool
or Jeremy Yallop's Deriving mechanism.

Function values can be difficult to exchange in both directions.  It
might be possible to encapsulate Erlang functions as an abstract Caml
type, with an appropriate "apply" primitive.  I don't know if this can
be made to work in the other direction, e.g. encapsulate Caml
functions as some opaque thing on the Erlang side.  At any rate, for
many applications, exchange of first-order data structures can be
enough.

If the Caml code and the Erlang code live in the same address space,
the actual exchange of data can be done through the C interfaces of
both languages.  This is what we did for the Caml/Java interface,
going through the Java Native Interface and OCaml's C interface.
The two GC can be made to cooperate.  However, data cycles that spawn
the two heaps will never be garbage-collected.

As others mentioned, it is possible to encapsulate Caml code and the
Caml runtime system as a DLL, at least for x86 under Linux and Windows.
For the Caml/Java interface, we used the reverse embedding: the Caml
code would link with the Java runtime system (as a library), which
would then load the Java code.

Apparently, Erlang makes it possible to communicate between separate
processes using byte streams.  This is an original feature that could
significantly simplify the interface: the Caml side could be written
entirely in Caml, bypassing low-level C interface code.

I guess that's all I can say at this point, but feel free to ask
questions.

- Xavier Leroy


  parent reply	other threads:[~2007-06-22  8:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-21  9:39 Ulf Wiger (TN/EAB)
2007-06-21  9:52 ` [Caml-list] " Joel Reymont
2007-06-21 10:15   ` Matthieu Dubuget
2007-06-21 10:28     ` Joel Reymont
2007-06-21 10:42       ` Ulf Wiger (TN/EAB)
2007-06-21 19:09       ` Pablo Polvorin
2007-06-21 10:34     ` Ulf Wiger (TN/EAB)
2007-06-21 12:00     ` Jon Harrop
2007-06-21 12:23       ` Matthieu Dubuget
2007-06-21 19:00         ` Pablo Polvorin
2007-06-22 10:22       ` Dmitry Bely
2007-06-22  8:02 ` Xavier Leroy [this message]
2007-06-22 11:57   ` Serge Aleynikov
2007-06-25  9:44   ` Ulf Wiger (TN/EAB)
2007-06-23  4:02 ` Jon Harrop
     [not found] ` <1182973204.24639.1197385329@webmail.messagingengine.com>
2007-06-27 21:07   ` Ulf Wiger (TN/EAB)
2007-06-28  8:22     ` Gabriel Kerneis
2007-06-28  8:38       ` Gabriel Kerneis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=467B8230.9090904@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=ulf.wiger@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).