Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Benjamin Canou <benjamin.canou@gmail.com>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Technical question about internal representation of functional values
Date: Sat, 01 Dec 2007 21:44:21 +0100	[thread overview]
Message-ID: <1196541861.28430.9.camel@benjamin-laptop> (raw)

Hi,

  I  have  a  strange  question,  for  which  I  have  a  working  but
incomplete, low level and  implementation dependent answer.  Maybe I'm
missing  a  less  tricky  solution,  so  I want  to  ask  people  who
understand the internal behaviour of OCaml better than I do.

  The context  is not  really important, but  let's say,  to simplify,
that I want to marshal closures in a controlled way (at source level).
  Basically, I have  a table of registered closures that  I want to be
able to export. These closures are explicitly declared as marshallable
in the source  by adding them to the table  with a dedicated function.
There is no way (as far as  I know) to build such a polymorphic table,
so I use some "not for the casual user" stuff for prototyping and will
rely on externals later.

  Before calling  the standard marshal function, I  explore the value,
and when I find  a closure which is in the table,  I replace it with a
descriptor block  (by using a high  block tag unused  in my prototype,
let's say  240). When I find  a closure which  is not in the  table, I
reject the value.
  This is kind of tricky but works well.  Now, I want some support for
partial applications of these closures  (and  marshal  the environment
along   with  the   descriptor  block).    Unfortunately,   a  partial
application is not easily detectable.

  My  current implementation  only  works with  ocamlopt, is  probably
highly platform and version dependent and does not satisfy me at all :
I unfold applications of "caml_curryN(_M)?".
  Another idea I  have in mind is to write  an assembly function which
behaves like the vm's application  by extending the closure and detect
this  function  (or  maybe this  application  function  exists  and is
bound to  an existing C symbol I can use to set Field(closure, 0) ?).

  So, is  there a cleaner way  to recognize partial  applications of a
specific closure by exploring a value ?

  Thanks for reading these strange questions and my dirty solutions.

Benjamin.


                 reply	other threads:[~2007-12-01 20:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1196541861.28430.9.camel@benjamin-laptop \
    --to=benjamin.canou@gmail.com \
    --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