Browse thread
what is the "best" block structure to code a tree structure?
-
Arkady Andrukonis
- Jon Harrop
- Goswin von Brederlow
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Goswin von Brederlow <goswin-v-b@w...> |
| Subject: | Re: [Caml-list] what is the "best" block structure to code a tree structure? |
Arkady Andrukonis <grazingcows@yahoo.com> writes:
> Hi,
>
> I would like to find the easiest block structure to represent nested leaves and nodes in a tree structure that works for OCaml. In Common Lisp there is the help of indentation, but I haven't found one for OCaml.
>
> We have one parent node composed of one leaf and a nested node which has another node with two leaves and a leaf (of the second node). To help illustrate the level of depth we can use numbers 10, 20, and 30.
> (*
> -------------------
> our type definition
> -------------------
> *)
> # type tree = Node of tree * tree | Leaf of int;;
> (*
> ------------
> and our tree
> ------------
> *)
> # Node ((Leaf 10), (Node ((Node ((Leaf 20),(Leaf 30))), Leaf 30)));;
> -: tree = Node (Leaf 10, Node (Node (Leaf 20, Leaf 30), Leaf 30))
Node ((Leaf 10),
......(Node
.........((Node
.............((Leaf 20),
..............(Leaf 30))),
..........Leaf 30)));;
How about that?
I don't get your numbering though. The 20 is too deep and the second
30 not deep enough imho.
Mfg
Goswin