From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 04E18BBCA for ; Thu, 3 Apr 2008 16:08:01 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnECABeC9EfRVYT7c2dsb2JhbACRVwEMAwQFCRSaAQ X-IronPort-AV: E=Sophos;i="4.25,599,1199660400"; d="scan'208";a="9153623" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Apr 2008 16:08:00 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m33E7s8C014076 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 3 Apr 2008 16:08:00 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnECABeC9EfRVYT7c2dsb2JhbACRVwEMAwQFCRSaAQ X-IronPort-AV: E=Sophos;i="4.25,599,1199660400"; d="scan'208";a="9153615" Received: from an-out-0708.google.com ([209.85.132.251]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Apr 2008 16:07:55 +0200 Received: by an-out-0708.google.com with SMTP id c24so783031ana.97 for ; Thu, 03 Apr 2008 07:07:54 -0700 (PDT) Received: by 10.100.123.11 with SMTP id v11mr24680268anc.98.1207231674513; Thu, 03 Apr 2008 07:07:54 -0700 (PDT) Received: from fry ( [68.48.11.159]) by mx.google.com with ESMTPS id 32sm4178638aga.20.2008.04.03.07.07.52 (version=SSLv3 cipher=OTHER); Thu, 03 Apr 2008 07:07:53 -0700 (PDT) Date: Thu, 3 Apr 2008 10:07:48 -0400 From: "Hezekiah M. Carty" To: Jacques Garrigue Cc: caml-list@inria.fr Subject: Re: [Caml-list] Unset or remove an OCaml callback registration Message-ID: <20080403140748.GA5408@fry> References: <3a360f590804021112r1cba67d9yc1715c08fb4a2e92@mail.gmail.com> <20080403.092612.89121596.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080403.092612.89121596.garrigue@math.nagoya-u.ac.jp> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Sender: "Hezekiah M. Carty" X-Miltered: at concorde with ID 47F4E4BA.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; unset:01 ocaml:01 ocaml:01 foo:01 foo:01 val:01 val:01 equality:01 wrote:01 caml-list:01 func:01 int:01 int:01 callback:02 callback:02 On Thu, 03 Apr 2008, Jacques Garrigue wrote: > From: "Hezekiah M. Carty" > > 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? Thank you very much for the response, Hez