Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] how to define a property list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] how to define a property list
On Fri, Apr 23, 2004 at 07:56:54PM +0200, Christoph Bauer wrote:
> 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. 

Could well be missing the point entirely here, but what about:

type 'a tree = Leaf of 'a | Node of 'a tree * 'a * 'a tree

and then use something simple like an assoc-list for storing the
properties, so your final type would be:

(string * string) list tree

eg:

let t = Node (Leaf [], [ "prop1", "value1" ], Leaf []);;
val t : (string * string) list tree = (* ... *)

This seems to separate out the 'treeness' from what is stored at each
node, so you can use generic algorithms to operate over the tree.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/

-------------------
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