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


Thank you for your comments, Xavier.

(It does seem as if some prototyping will take
place in the near future.)

Xavier Leroy wrote:

> 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.

One might also have a look at the Erlang binary type. (:

Actually, this is not as corny as it sounds.
You could pass a parsing declaration in the form
of Erlang bit syntax expressions, and compile an
encode/decode module on the fly on the Erlang side.

Examples of the bit syntax can be found here:
http://www.erlang.org//doc/programming_examples/bit_syntax.html#4

And there's a (currently experimental) new version
of binary handling called "binary comprehensions"
(c.f. list comprehensions, but on bits or bytes)

http://user.it.uu.se/~pergu/papers/erlang05.pdf

Here's a very small example of decoding with the
help of binary comprehensions, from above paper:

uudecode(UUencodedBin) ->
<<(X-32):6 || X <<- UUencodedBin, 32=<X, X=<95>>.

The native code compiler in Erlang understands 
the bit syntax and optimizes the matching, so working
directly on binary objects in Erlang is both reasonably
expressive and quite efficient.

Large binaries are reference-counted in Erlang,
and passed by pointer reference between processes
(under the covers - conceptually, they're copied).


> 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.

Function values are only passed by reference between 
erlang nodes, so evaluating them only works if the 
right module is loaded on the remote end (a hash value
is passed along to ensure that the wrong function isn't
evaluated.) Even if it can't be evaluated, it can of 
course be passed along as an opaque value.

If this representation were used when communicating,
it might be possible (but perhaps quite strange) to 
represent OCaml functions in the same way, such that 
they cannot be confused with Erlang functions.

This would make it possible to pass function values
by reference between the two environments, but each
reference would only actually be callable in its native
environment.

In order to send an OCaml function value through the 
Erlang environment to an OCaml recipient, I guess an
appropriate encapsulation is needed, which would look
like a binary object to the Erlang side.

BR,
Ulf W


  parent reply	other threads:[~2007-06-25  9:44 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
2007-06-22 11:57   ` Serge Aleynikov
2007-06-25  9:44   ` Ulf Wiger (TN/EAB) [this message]
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=6616D98C65DD514BA2E1DDC5F9223155022BC365@esealmw115.eemea.ericsson.se \
    --to=ulf.wiger@ericsson.com \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    /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).