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 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 69B26BC0A for ; Wed, 23 May 2007 13:21:02 +0200 (CEST) Received: from moldavcable.com (moldavcable.com [89.187.37.10]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4NBKeKC013531 for ; Wed, 23 May 2007 13:20:49 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by moldavcable.com (Postfix) with ESMTP id 337906B662 for ; Wed, 23 May 2007 14:19:47 +0300 (EEST) Received: from moldavcable.com ([127.0.0.1]) by localhost (mlc-gw-l.moldavcable.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 30290-02 for ; Wed, 23 May 2007 14:19:30 +0300 (EEST) Received: from kas30pipe.localhost (localhost.localdomain [127.0.0.1]) by moldavcable.com (Postfix) with SMTP id 244696B76C for ; Wed, 23 May 2007 14:19:26 +0300 (EEST) Received: from pm053.mlc.local (pm053 [192.168.50.53]) by moldavcable.com (Postfix) with ESMTP id AF9E86B662 for ; Wed, 23 May 2007 14:19:24 +0300 (EEST) Date: Wed, 23 May 2007 14:20:05 +0300 From: dmitry grebeniuk X-Mailer: The Bat! (v3.85.02) Home Reply-To: dmitry grebeniuk Organization: Moldavcable X-Priority: 3 (Normal) Message-ID: <151158176.20070523142005@moldavcable.com> To: caml-list@inria.fr Subject: creating a functional value from C MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release X-SpamTest-Info: Not protected X-Virus-Scanned: by amavisd-new at moldavcable.com X-Miltered: at discorde with ID 46542388.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; grebeniuk:01 ocaml:01 val:01 val:01 def:01 def:01 camlparam:01 ocaml:01 rewrite:01 functions:01 dmitry:01 dmitry:01 func:01 func:01 int:01 Hello. I want to create a functional value from C world, which can be called from OCaml. Something to make this code work: external create_func_val : int -> (string -> string) = "c_create_func_val"; value fv = create_func_val 123; print_string (fv "abc"); print_string (fv "def"); Real situation is more complex -- functions "c_create_func_val" and "fv" both has side effects, so I can't just rewrite last lines as "print_string (create_func_val 123 "abc"); print_string (create_func_val 123 "def");", moreover, the real address that will be stored in "fv"-closure becomes known only in function "c_create_func_val", and it is the address of C function that follow all gc-related conventions (takes and returns "value"s, uses CAMLparam and so on). As a simplification, "fv" should not hold any ML values in its environment. Is it possible? If yes, then how to do it? Reading OCaml sources hadn't helped me. -- WBR, dmitry mailto:gds-mlsts@moldavcable.com