caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk)
To: caml-list@inria.fr
Subject: Re: [Caml-list] create a closure in external C function?
Date: 6 Mar 2001 18:58:56 GMT	[thread overview]
Message-ID: <slrn9aacrg.ucc.qrczak@qrnik.zagroda> (raw)
In-Reply-To: <20010306180128.B12522@pauillac.inria.fr>

Tue, 6 Mar 2001 18:01:28 +0100, Xavier Leroy <Xavier.Leroy@inria.fr> pisze:

> As Fabrice noted, the hard part is to deal with arbitrary many C
> function types, determined dynamically. There, you'd need some kind
> of dynamic invocation interface for C functions, and I don't know
> of any C library that provides this in a portable or semi-portable
> fashion.

What about another issue: converting a function closure to a C
function pointer? This too cannot be done portably, can be done
unportably, is needed in the functional programming context, and
I don't know any C library or compiler extension which provides
it (besides gcc's downward closures, but they are not sufficient).
A generic C interface would probably express it as partial application.

Semi-standard Haskell's foreign function interface provides this
(converting a Haskell's function closure to a C function pointer).
There is a function which frees the data assiociated with a function
pointer produced that way.

Last time I looked at this, I hadn't found this functionality in OCaml.
You can at most register OCaml's functions under textual names. This
interface is too limited. You can't even unregister them.

Should OCaml provide this? I haven't really used OCaml much, but
imagine that currently you have to rely on whatever poor man's closure
mechanism was provided by the C library you are interfacing to.
E.g. gtk+ uses the standard C trick of bundling a callback function
pointer with a void * value which is passed to the function as an
additional argument.

Designers of some other libraries were not aware of the fact that
there exist languages which treat functions as data, e.g. readline
wants just function pointers, and it even doesn't let the programmer
know when the function pointer is no longer needed.

The implementation of this conversion must of course build
heap-allocated machine code at runtime, hiding the data pointer
inside it.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-03-06 18:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-06  9:29 Chris Hecker
2001-03-06 10:50 ` Fabrice Le Fessant
2001-03-06 17:01 ` Xavier Leroy
2001-03-06 18:19   ` Chris Hecker
2001-03-07  3:23     ` Fergus Henderson
2001-03-06 18:58   ` Marcin 'Qrczak' Kowalczyk [this message]
2001-03-06 19:13     ` Chris Hecker
2001-03-06 21:16       ` Marcin 'Qrczak' Kowalczyk
2001-03-06 22:56         ` Chris Hecker
2001-03-07  0:22           ` Marcin 'Qrczak' Kowalczyk
2001-03-07  0:44             ` Chris Hecker
2001-03-07  8:49               ` Marcin 'Qrczak' Kowalczyk

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=slrn9aacrg.ucc.qrczak@qrnik.zagroda \
    --to=qrczak@knm.org.pl \
    --cc=caml-list@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).