Hello bahadyr,
Before going into data Tree alpha, consider a simpler version, tree that stores only an integer in it.
Now, a (binary) tree will consist of nodes. A node can be an Empty node or store an integer and link to two other nodes (a left one and a right one). So, basically we have only two types of nodes. We represent this in this way:
data Node = Empty
| ValueNode Int, Node, Node -- An integer, a left node and a right node
We construct this node this way:
n = Empty --creates an empty node
n = ValueNode 3, Empty, Empty -- A node containing only one value
n = ValueNode 3, (Node 4 Empty Empty), (Node 5 Empty Empty) -- 3 with left 4 and right 5
This has a limitation: we can store only integers in it. Let's remove that limitation by using Type Variables.
Instead of saying that Node stores only Int, we must say that Node needs a Type first, then it stores values of that type in it.
So, instead of just:
data Node
we have
data Node a = Empty -- a is the type variable
Now, Node uses that a instead of Int