[clean-list] questions about Clean learning

RT Happe rthappe at web.de
Sat Jul 23 18:49:56 MEST 2005


Jigang Sun wrote:
> I do not understand the data structure of "::Tree a = Node a [Tree 
> a]". Would anyone please give an instance of it.

A couple of such trees:

oak = Node 0 []
chestnut = Node 1 [Node 2 [Node 3 []], Node 4 []]
oakchest = Node 5 [oak, chestnut]
poplar = Node "Jill" trees
where
     trees = [Node "Joe" trees]

The given type definition offers only one data constructor, the 
two-place Node.  As the other examples you ask about show, algebraic 
types (or data grammars) may be more complex.  Here's a sick variant of 
Tree with three data constructors: Nude, Loaf, Emptree, of arity 2, 1, 
0 respectively.

::Three a b = Nude a [Three a b] | Loaf b | Emptree

wormwood = Nude 5 [Emptree, Nude 6 [Loaf "gospodin"]]

Morale:  Use the data constructors on the right hand side of the 
algebraic type definition to construct data of that type.

rthappe



More information about the clean-list mailing list