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 q45GN05e009757 for ; Sat, 5 May 2012 18:23:00 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuQBAARTpU/ZSMDdgGdsb2JhbABFsnQiAQELCwsFFgMkggwBAQQBJxM/BQsLGAklDwEEKCEThhKBbQEJCa9PH4oLin8Bhh8Em2GNSoFc X-IronPort-AV: E=Sophos;i="4.75,536,1330902000"; d="scan'208";a="156890538" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 May 2012 18:22:54 +0200 Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate01.web.de (Postfix) with ESMTP id 6F8C81ADB79E8 for ; Sat, 5 May 2012 18:22:54 +0200 (CEST) Received: from frosties.localnet ([95.208.118.96]) by smtp.web.de (mrweb001) with ESMTPA (Nemesis) id 0Lzate-1S5L5g083O-014oj9; Sat, 05 May 2012 18:22:54 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.77) (envelope-from ) id 1SQhkz-00056c-5o; Sat, 05 May 2012 18:22:53 +0200 From: Goswin von Brederlow To: Andreas Rossberg Cc: Goswin von Brederlow , caml-list@inria.fr References: <87r4uykb09.fsf@frosties.localnet> <8A61AE0A-950A-4AE0-912F-2B7A233C7E8A@mpi-sws.org> Date: Sat, 05 May 2012 18:22:53 +0200 In-Reply-To: <8A61AE0A-950A-4AE0-912F-2B7A233C7E8A@mpi-sws.org> (Andreas Rossberg's message of "Sat, 5 May 2012 16:48:46 +0200") Message-ID: <87havu4mxu.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:gfodDYpk70fGKLUVgHyjIvwERmrS16a1+wyVRE8whoT 8Oxu1RCYDiGlFAFtvPUlpEXDt3qEgVwWPL08dn9m/bzHl8opLS zAgqOFiH+kTbNCcDzLKdGiJA9GJDL6FsnPgsOrBU5C7Aeckr/5 lVqd+8APzjoTVWWA34QcYWV0j3dDJdhIquf2cTW632IQMV8Mj0 IBDnEtkU/Od5YDe38ezdQ== Subject: Re: [Caml-list] A shallow option type Andreas Rossberg writes: > On May 5, 2012, at 15.33 h, Goswin von Brederlow wrote: >> What I want is a >> >> type 'a shallow = NULL | 'a (constraint 'a != 'b shallow) > > This is a form of negation, which cannot be expressed in conventional > type systems. Just consider what it should mean in the presence of > type abstraction: if you have > > M : sig > type t > ... > end > > would `M.t shallow` be a legal type? You couldn't decide that properly > without requiring that _every_ abstract type in every signature is > annotated with a constraint saying that it is "not shallow". True, so abstract types would have to be forbidden too becauseit can't be decided wether they are save or not. Since 'a shallow is an abstract type that would also forbid 'a shallow shallow. So "constraint 'a != " would be the right thing. >> 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. > > And how do you know that nobody else implements a _different_ type, > say shallow2, that does the same thing? And a third party then > constructs a value of type `int shallow2 shallow`? I don't and I can't. But such a type would be abstract so wouldn't be allowed by the above (reject abstract types). > It seems to me that what you want effectively is a special case of non- > disjoint union. Unfortunately, those are known to come with all kinds > of problems, such as not being compositional. > > /Andreas What I want is to have an array of type t ={ ... } (* Unit.t *) and a matrix of type tile = { ... mutable unit : Unit.t option; } that I can safely access from a C thread in parallel with ocaml without having to look the runtime system or individual tiles (the array and matrix would both be created outside the ocaml heap). The problem I have is that tile.unit <- Some unit will allocate an option block on the heap and accessing that from C while the GC runs causes a race condition. What I don't want to do is use type tile = { ... mutable unit : Unit.t; } tile.unit <- Obj.magic 0 since then trying things out in the toplevel causes segfaults when the pretty printer prints the tile.unit and it would be easy to forget to compare the tile.unit to Obj.magic 0 on every use. I know my shallow type is basically nothing else but it adds a level of savety to it. Idealy I would even love to write match tile.unit with | NULL -> () | unit -> do_something unit I guess some camlp4 magic could be used to transform such a match into match Shallow.as_option tile.unit with | None -> () | Some unit -> do_something unit or similar constructs. MfG Goswin