From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DC6ADBC88 for ; Mon, 7 Feb 2005 12:58:15 +0100 (CET) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j17BwFYX002486 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 7 Feb 2005 12:58:15 +0100 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1Cy7Ww-00069M-00 for ; Mon, 07 Feb 2005 11:58:14 +0000 Date: Mon, 7 Feb 2005 11:58:14 +0000 Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Creating a tree type Message-ID: <20050207115814.GA22127@furbychan.cocan.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.28i From: Richard Jones X-Miltered: at nez-perce with ID 420757D7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 ocaml's:01 nodes:01 recursive:01 defintion:01 ocaml:01 threading:01 threading:01 pointers:01 nodes:01 sandbox:01 lib:01 notepad:01 tar:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Tue, Feb 08, 2005 at 12:41:37AM +1300, Jonathan Roewen wrote: > Hi, > > What would be the best approach to creating a tree type such that at > each node, it has some sort of reference to the parent node? Is this > an example of when ocaml's OO side would be more useful? > > Basically, I'm creating a UI for my OS; since events will typically > bubble from leaf nodes up through their ancestors until either the > event has been handled or have reached the root node, being able to > reference the parent node efficiently (and easily) is a requirement. > > I've tried a recursive type, but both the defintion and code to make > use of it is damn ugly and complicated--there just has to be a better > way to do this sort of thing nicely in ocaml. I had a similar problem - threading mail using JWZ's threading algorithm. It requires you maintain a tree with pointers to parent and/or root nodes. You can find the implementation (not by me, but by Radu Grigore) in http://sandbox.merjis.com/_file/cocanwiki-1.3.8.tar.gz , in file scripts/lib/cocanwiki_mail.ml Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com