caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Technical question about internal representation of functional values
@ 2007-12-01 20:44 Benjamin Canou
  0 siblings, 0 replies; only message in thread
From: Benjamin Canou @ 2007-12-01 20:44 UTC (permalink / raw)
  To: caml-list

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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-12-01 20:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-01 20:44 Technical question about internal representation of functional values Benjamin Canou

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