From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q45DY59Q001972 for ; Sat, 5 May 2012 15:34:05 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsgBAP8qpU/ZSMDdgGdsb2JhbABFsnQiAQELCwsFFgMkgk17NAEEKIgzARKZP5ZKH4oLjXmDJgSbYY1K X-IronPort-AV: E=Sophos;i="4.75,536,1330902000"; d="scan'208";a="156880390" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 May 2012 15:34:00 +0200 Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate01.web.de (Postfix) with ESMTP id B05EF1ADB8A5B for ; Sat, 5 May 2012 15:33:59 +0200 (CEST) Received: from frosties.localnet ([95.208.118.96]) by smtp.web.de (mrweb002) with ESMTPA (Nemesis) id 0MX0lw-1ScoCJ1xhc-00W17t; Sat, 05 May 2012 15:33:59 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.77) (envelope-from ) id 1SQf7W-0004cz-U1 for caml-list@inria.fr; Sat, 05 May 2012 15:33:59 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Date: Sat, 05 May 2012 15:33:58 +0200 Message-ID: <87r4uykb09.fsf@frosties.localnet> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Provags-ID: V02:K0:6msm3qrPCgFh25k6iC7doQH8E1XXNcKp8LTJ+tzALfF KT1Onuf3fDBpmZrGapQ202z39v4boVLrxC8a3C+e6hRlWsfpve bZTe5TImYQJjYChlXpxOfJCifdgropuqf8bX/IrFlkRB/xbXEe 61WnBX18OkMa1e5n+SG6zEJMwRBkt+g0Jouldd0wJsAO+iFX/F E11UAY4ZUko6qbXbDIZUg== Subject: [Caml-list] A shallow option type Hi, I wish there was an option type that would work without extra indirection (or more importantly without extra allocation of an ocaml value when setting it to something). Why? I'm interfacing with C in a multithreaded way. The data is allocated on the C side so it won't be moved around by the GC. The ocaml side will modify data and the C side will utilize it. Now if ocaml changes a multable 'a option then it will allocate a block for "Some x" and the GC will move that block around during compaction. Which means the 'a option can't be safely used without holding the runtime system lock. Which then means the threads can't run in parallel. What I want is a type 'a shallow = NULL | 'a (constraint 'a != 'b shallow) I have some ideas on how to implement this in a module as abstract type providing get/set/clear functions, which basically means I map None to a C NULL pointer and Some x to plain x. I know x can never be the NULL pointer, except when someone creates a 'a shallow shallow and sets Some None. That would turn into simply None. Is it possible to somehow declare the constraint that 'a in 'a shallow must not be itself a 'b shallow? MfG Goswin