caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gordon Henriksen <gordonhenriksen@mac.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Unset or remove an OCaml callback registration
Date: Thu, 3 Apr 2008 10:25:08 -0400	[thread overview]
Message-ID: <98127602-A30D-4910-9991-D4C9818185DE@mac.com> (raw)
In-Reply-To: <20080403140748.GA5408@fry>

On Apr 3, 2008, at 10:07, Hezekiah M. Carty wrote:

> On Thu, 03 Apr 2008, Jacques Garrigue wrote:
>
>> From: "Hezekiah M. Carty" <hcarty@atmos.umd.edu>
>>> Is this possible, either from the C or OCaml side without making  
>>> the callback associate with "foo" an option type (use  
>>> (Callback.register "foo" (Some some_func)) to set a callback and  
>>> (Callback.register "foo" None) to clear it)?
>>
>> Since Callback.register has type: string -> 'a -> unit you are not  
>> limited by the ocaml type system. So you can reset your value with
>>  Callback.register "foo" 0
>> and check for equality with Val_int(0) on the C side. (Note that  
>> you must initialize the value to 0 at program startup, because the  
>> default for an unitialized value is 0 which is not Val_int(0))
>
> If I wrap the C interface in an OCaml module, would it be enough to  
> include:
>
> let () = Callback.register "foo" 0
>
> in the top level of the module to have this command execute when the  
> module is loaded?  Or does the module user have to do some explicit  
> initialization?


I've used this technique, although I did have initialization ordering  
problems. The outer module is not necessarily initialized before the  
inner one. In my case, the initialization was idempotent, so I simply  
repeated it in each submodule.

— Gordon


      reply	other threads:[~2008-04-03 14:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-02 18:12 Hezekiah M. Carty
2008-04-03  0:26 ` [Caml-list] " Jacques Garrigue
2008-04-03 14:07   ` Hezekiah M. Carty
2008-04-03 14:25     ` Gordon Henriksen [this message]

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=98127602-A30D-4910-9991-D4C9818185DE@mac.com \
    --to=gordonhenriksen@mac.com \
    --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).