Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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


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.


Richard Jones.
Merjis Ltd. - improving website return on investment
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: