caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: Maas-Maarten Zeeman <mmzeeman@xs4all.nl>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] announce: callbacks-0.1
Date: Thu, 08 Sep 2005 23:24:07 +0200	[thread overview]
Message-ID: <4320ABF7.7020009@univ-savoie.fr> (raw)
In-Reply-To: <4320A68E.1060608@xs4all.nl>

Maas-Maarten Zeeman a écrit :
> 
> Hello,
> 
>> link: third item of:
>>
>> http://www.lama.univ-savoie.fr/~raffalli/?page=soft&lang=en
>>
>> comment and idea are welcome !
>>
> 
> Sounds like a nice idea. As the author of ocaml-expat a binding I've 
> also worked with c -> ocaml callbacks.
> 
> It is not really clear to me what problem you are trying to solve. It is 
> not very difficult for somebody writing a Ocaml binding to come up with 
> a solution which is easy to call an ocaml function value from c.
> 
> What I did was create one fixed c-callback functions which:
> 
> receive c-parameters
> transform them to ocaml-values
> lookup the ocaml callback "cb" in a tuple (set earlier from ocaml),

This is that step I want to avoid ... not mainly for performance, but 
because there are some cases where you do not know which callback you 
should call (this was the case for one of the glut callback, I don't 
recall which one, and it was a bit tricky for glutTimer). It happens 
that in glut, the current window or current menu is properly set before 
calling the callback ... but there may be other library, more purely 
functional, with no concept of "current window" ...

The other reason, is that it makes it easier to writte the bindings for 
the library (no thinking required and therefore less bug) ! and does not 
make it that much complex for the user.

If you really need "dynamic" callback with arbitrary closure, then you 
can implement your trick above mine in OCaml.

By expending my work, we could write and use bindings for a C library 
like glut without writing a line of C, except to convert data structure 
from C to OCaml if you really need that.

This could divide the size of the glut binding by a factor 2 or 3 ...
which is important !

> apply cb to the ocaml-values,
> etc, etc
> 
> The ocaml programmer just has to deal with normal ocaml callback 
> function values (which can be partially applied, unnamed, etc). These 
> will be stored via c in a tuple. The value pointing to this tuple is 
> registered as 1 global root. If you have large amounts of callbacks it 
> would probably work with a simple hash table too. Then you only have to 
> write/generate 1 c-callback function (per c-signature) which takes care 
> of calling an unlimited amount of caml callbacks.
> 
> Its interesting to have the c-wrapper function generated as it would 
> prevent hard to debug gc problems.
> 
> Regards,
> 
> Maas


  parent reply	other threads:[~2005-09-08 21:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-08 16:31 Christophe Raffalli
     [not found] ` <4320A68E.1060608@xs4all.nl>
2005-09-08 21:24   ` Christophe Raffalli [this message]
2005-09-08 23:31     ` Bardur Arantsson
2005-09-09  6:30       ` Bardur Arantsson
2005-09-10  7:04         ` [Caml-list] " Xavier Leroy
2005-09-10  7:31           ` Bardur Arantsson
2005-09-10 13:04           ` [Caml-list] " Yaron Minsky
2005-09-10 21:02           ` caml_register_unmutable_global_root Christophe Raffalli

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=4320ABF7.7020009@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@inria.fr \
    --cc=mmzeeman@xs4all.nl \
    /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).