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

[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: Christoph Bauer Subject: Re: [Caml-list] how to define a property list
```Hi,

> 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
^^^^^^ this could be a int or a string in the same 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.

Of course I could convert my integer to strings (and back),
but this solutions isn't so satisfying

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

```