[Haskell-cafe] A binary tree

paolo veronelli paolo_veronelli at yahoo.it
Sun Jul 4 09:00:20 EDT 2004

I want to build a binary tree where each leaf is a string of "L" and "R" 
defining their position from the top

This should be done without context isn't it?

data Tree a = Fork (Tree a) (Tree a) | Leaf a deriving Show

t =Leaf ""

treeGrower :: Tree a -> Tree a
treeGrower (Leaf a )= treeGrower (Fork (Leaf (a++"1")) (Leaf (a++"2")))
treeGrower (Fork l r)  = Fork (treeGrower l) (treeGrower r)

ghci says:
     Cannot unify the type-signature variable `a' with the type `[a1]'
         Expected type: [a1]
         Inferred type: a
     In the first argument of `(++)', namely `a'
     In the first argument of `Leaf', namely `(a ++ "1")'

I don't get it.........

More information about the Haskell-Cafe mailing list