caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <yallop@gmail.com>
To: Malcolm Matalka <mmatalka@gmail.com>
Cc: "David Sheets" <sheets@alum.mit.edu>,
	"Jeremie Dimino" <jdimino@janestreet.com>,
	"Christoph Höger" <christoph.hoeger@tu-berlin.de>,
	"caml users" <caml-list@inria.fr>
Subject: Re: [Caml-list] Save callbacks from OCaml to C
Date: Thu, 4 Feb 2016 11:29:20 -0800	[thread overview]
Message-ID: <CAAxsn=GCrYp7PT78JRc1gc3ngjk2sBKCtZ=2HD8Fj8dFf1++Eg@mail.gmail.com> (raw)
In-Reply-To: <86io25q6lt.fsf@gmail.com>

On 3 February 2016 at 23:26, Malcolm Matalka <mmatalka@gmail.com> wrote:
> Jeremy Yallop <yallop@gmail.com> writes:
>> Storing the functions in a table, and removing them automatically
>> after they're called is one approach.  An alternative is to use the
>> new Ctypes.Roots module, which will be available in the next release:
>>
>>    https://github.com/ocamllabs/ocaml-ctypes/blob/182a9e64src/ctypes/ctypes.mli#L419-L435
>
> Thank you for the thorough response.  It seems like Ctypes.Roots might
> solve my problem, although the URL gives me a 404.

Oops.  Here's a working URL:

https://github.com/ocamllabs/ocaml-ctypes/blob/182a9e64/src/ctypes/ctypes.mli#L419-L434

> Do you have an estimation of when this will be released (or anything someone like
> myself can do to help?)

There are a few issues left to address before the next release:

   https://github.com/ocamllabs/ocaml-ctypes/milestones/ctypes%200.5

Thanks for the offer of help!  Feedback on the Ctypes.Roots design
would be appreciated.  More generally, some of the outstanding issues
might be fixable by a motivated beginner, e.g.

   https://github.com/ocamllabs/ocaml-ctypes/issues/316
   https://github.com/ocamllabs/ocaml-ctypes/issues/267
   https://github.com/ocamllabs/ocaml-ctypes/issues/106

> What kind of sucks about that is the wrapper needs to be unique to each
> type of closure that gets called, there doesn't seem like a really
> generic way to do this wrapping.  Am I on the wrong track?

If you're only storing the closures in the table, and don't need to
retrieve and call them, then you can use a type which hides the type
of the closure in some way.  One approach is to use Obj.t, and convert
each closure using Obj.repr as you store it.  If using Obj makes you
uneasy (as it generally ought to, although it's currently safe in this
case) then an alternative is to use an existential type, like this:

   type t = T : _ -> t

which allows you to wrap any type of value, regardless of its type:

  # [T (+); T not; T 3; T ""];;
  - : t list = [T <poly>; T <poly>; T <poly>; T <poly>]

  reply	other threads:[~2016-02-04 19:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03 10:54 Christoph Höger
2016-02-03 11:48 ` Jeremie Dimino
2016-02-03 12:26   ` Malcolm Matalka
2016-02-03 13:44     ` David Sheets
2016-02-03 18:02       ` Jeremy Yallop
2016-02-03 20:15         ` Malcolm Matalka
2016-02-04  0:14           ` Jeremy Yallop
2016-02-04  7:26             ` Malcolm Matalka
2016-02-04 19:29               ` Jeremy Yallop [this message]
     [not found]   ` <56B1EC33.2090303@tu-berlin.de>
2016-02-03 13:49     ` Jeremie Dimino
2016-02-03 14:38       ` Christoph Höger

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='CAAxsn=GCrYp7PT78JRc1gc3ngjk2sBKCtZ=2HD8Fj8dFf1++Eg@mail.gmail.com' \
    --to=yallop@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=christoph.hoeger@tu-berlin.de \
    --cc=jdimino@janestreet.com \
    --cc=mmatalka@gmail.com \
    --cc=sheets@alum.mit.edu \
    /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).