Version franaise
Home About Download Resources Contact us
Browse thread
Annotated trees
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: [Caml-list] Annotated trees
> 1. Pattern-matching is more readable because the most important piece of
> information comes first:
>
>   `Leaf (_, s) -> ...
>  | `Node (_, l) -> ...
>
> instead of:
>
>   (_, `Leaf s) -> ...
>  | (_, `Node l) -> ...

I'm not sure I agree on this one since in the second case the
parentheses are not needed. And if you put the annotation in the
second component (as you suggest your second message) then we are back
to most important first and without parentheses :

let f = function
| `Leaf s, _ -> ...
| `Node l, _ -> ...

> 3. It is possible to not annotate certain kinds of nodes, or to have different
> types of annotations depending on the kind of node.

That's true and certainly a good argument for the second form if you
already know the type of your annotations and have such needs. However
if you want to keep that polymorphic (the annotation is a convenience
for the client) it results in a type variable per case which becomes
heavy.

> 4. The tuple version feels like there are 2 different definitions of a tree
> node, i.e. it is easy to get confused about whether an annotated node (the
> pair) or an non-annotated node (second member of the pair) is expected in one
> given place.

I can understand that. It's true that it may make you think that you
are able to get a non-annotated value by just dropping the first
component. On the other hand the rule is quite simple, you always work
with pairs, period.

> 5. I got this habit and therefore I won't change my mind and reject all
> rational arguments against it ;-)

Yes, that's mainly a discussion about taste.

Thanks for your comments,

Daniel