From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA28352; Fri, 23 Apr 2004 19:50:58 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 TAA28425 for ; Fri, 23 Apr 2004 19:50:57 +0200 (MET DST) Received: from mail-in-03.arcor-online.net (mail-in-03.arcor-online.net [151.189.21.43]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3NHoujq004997 for ; Fri, 23 Apr 2004 19:50:57 +0200 Received: from diebuntekuh.de (dialin-212-144-186-066.arcor-ip.net [212.144.186.66]) by mail-in-03.arcor-online.net (Postfix) with ESMTP id 4F9E5C1324E for ; Fri, 23 Apr 2004 19:50:55 +0200 (CEST) Received: by diebuntekuh.de (Postfix, from userid 500) id 9D3C1608EC0; Fri, 23 Apr 2004 19:56:54 +0200 (CEST) To: OCaml List Subject: [Caml-list] how to define a property list From: Christoph Bauer Date: Fri, 23 Apr 2004 19:56:54 +0200 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; bauer:01 bauer:01 lisp-like:01 alist:01 val:01 val:01 3..:99 expr:01 .25:99 shifted:01 inherit:01 mutable:01 mutable:01 int:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi List, I want to create a tree. This tree should be a very simple accessible for algorithms and easy to understand. The nodes in the tree can have different properties of different types. An example of such a tree is the DOM-tree in JavaScript. There are several ways how to design such a tree. 1.) Using Records. Each node is a records, and the records contain a field for each possible property. Maybe a better approach is a type like this type ('a,'b) node = { ; mutable properties : 'a * 'b list } The list `properties' should be a key-value list. A Lisp-like alist would be perfect. Unfortunately the type 'b isn't fix. It can be string or int or something completely different. 2a) Using dynamic typing. type property_value = Int of int | String of String. type 'a node = { ; mutable properties : 'a * property_value list } If this is the solution, I'll better switch to Scheme, which has better support for dynamic types ;-) 2b) Add for each type a property list to node. type 'a node = { ; mutable int_properties : 'a * int list mutable string_properties : 'a * string list ... } This is my preferred solution so far. 3) Using OOP. (I'm not sure, whether OOP in general is good or bad.) class node = object end;; class ['a, 'b] sub_node a b= object(s) inherit node val mutable property1 : 'a = a ; val mutable property2 : 'b = b; method property1 = property1; method set_property1 = property1 method property2 = property2; method set_property2 = property2 end;; (* lot of typing for nothing so far*) let a = new sub_node 1 "a" :> node;; Question: How can I now access property1? Thanks for comments, Christoph Bauer -- beginfig(1)u=3cm;draw fullcircle scaled 2u;x0=x1=y1=x2=y3=0;-y0=y2=x3=1u; filldraw z0..{left}z1{left}..z2{curl 1}..z3..z0..cycle;def t(expr p)=fullcircle scaled .25u shifted(0,p*u);enddef;unfill t(.5);fill t(-.5);endfig;bye ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners