From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 8E746BB81 for ; Sat, 18 Dec 2004 21:06:55 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBIK6tDC005184 for ; Sat, 18 Dec 2004 21:06:55 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA17034 for ; Sat, 18 Dec 2004 21:06:54 +0100 (MET) Received: from mta05-winn.mailhost.ntl.com (mailhost.ntl.com [212.250.162.8]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBIK6sao005181 for ; Sat, 18 Dec 2004 21:06:54 +0100 Received: from aamta02-winn.mailhost.ntl.com ([212.250.162.8]) by mta05-winn.mailhost.ntl.com with ESMTP id <20041218200653.ZHGR24912.mta05-winn.mailhost.ntl.com@aamta02-winn.mailhost.ntl.com>; Sat, 18 Dec 2004 20:06:53 +0000 Received: from [80.4.70.84] by aamta02-winn.mailhost.ntl.com with ESMTP id <20041218200653.VWR11644.aamta02-winn.mailhost.ntl.com@[80.4.70.84]>; Sat, 18 Dec 2004 20:06:53 +0000 Message-ID: <41C48DDB.4010707@ntlworld.com> Date: Sat, 18 Dec 2004 20:06:51 +0000 From: "chris.danx" User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] Type problem... possible design problem References: <41C37CF7.5050400@ntlworld.com> <200412180807.05925.jon@jdh30.plus.com> <41C43E79.1040502@ntlworld.com> <20041218152759.GA12095@annexia.org> In-Reply-To: <20041218152759.GA12095@annexia.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41C48DDF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41C48DDE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 wrote:01 variants:01 subgraphs:01 val:01 val:01 subtrees:01 ntlworld:98 ...:98 ...:98 node:01 node:01 hmm:01 leaf:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: Richard Jones wrote: > On Sat, Dec 18, 2004 at 02:28:09PM +0000, chris.danx wrote: > >>My concern with variants is sharing subgraphs in graphs, will they be >>shared or copied? > > A tree structure like this should be stored shared: > > type 'a tree = Leaf of 'a | Node of 'a tree list > > You can prove this; for instance: > > # let n = ref 1;; > val n : int ref = {contents = 1} > # let t = Leaf n;; > val t : int ref tree = Leaf {contents = 1} > # let tree = Node [t; t];; > val tree : int ref tree = Node [Leaf {contents = 1}; Leaf {contents = 1}] > # n := 2;; > - : unit = () > # tree;; > - : int ref tree = Node [Leaf {contents = 2}; Leaf {contents = 2}] Hmm... this looks like it shows two subtrees hold the same reference but it does not to me look like it proves the structure is shared, only that references work as expected. Perhaps I can use type 'a sceneGraph = Leaf of 'a | IntNode of 'a * 'a sceneGraph list | SharedNode of 'a sceneGraph ref to achieve what I want. Chris