Browse thread
Unset or remove an OCaml callback registration
-
Hezekiah M. Carty
-
Jacques Garrigue
-
Hezekiah M. Carty
- Gordon Henriksen
-
Hezekiah M. Carty
-
Jacques Garrigue
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2008-04-03 (14:25) |
From: | Gordon Henriksen <gordonhenriksen@m...> |
Subject: | Re: [Caml-list] Unset or remove an OCaml callback registration |
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