Thank you Bob,
your example clarified how actually using such data type would appear in haskell. I naively thought it would be as simple as defining a regular list, but i see it is slightly more strict than that. I appreciate your help!

Vadali

On Tue, Jul 13, 2010 at 11:18 AM, Thomas Davie <tom.davie@gmail.com> wrote:

On 13 Jul 2010, at 10:11, Shlomi Vaknin wrote:

> Thank you all for replying!
>
> I am really beginning my baby steps in this fascinating language, and was just wondering if it was possible to naturally scan lists with arbitrary lists (aka trees :) ).

Trees aren't lists, Trees are trees...  Here's how you create one*

data Tree a = Leaf
            | Branch a [Tree a]

This roughly says, a tree can be made up of two possible things... First, it could be a leaf, and secondly, it could be a branch with an element at it, and a list of subtrees.

Some example trees using this data type:

1) Leaf
2) Branch 5 []
3) Branch 5 [Leaf]
4) Branch 5 [Branch 10 [], Branch 20 [], Leaf, Branch 50 [Branch 10 [], Leaf]]

When you have really strong typing, you also have very well specified types.  You don't just use a list as if it were a tree, you declare what a tree is.

Bob

* In this case an arbitrarily branching tree, we could ofc declare different forms of tree here.