
Anybody? thanks spot135 wrote:
Hi,
Ok what im trying to do is replace an element in an n-ary and display the completed tree.
So this is what ive got so far.
data Tree a = Empty |Leaf a|Branch a [Tree a] deriving (Show)
replace :: Eq a=>a->a->Tree a -> (Tree a)
replace x y Empty = Element x
replace x y (Leaf z) | x==z = (Leaf y) -- | otherwise =
replace x y (Branch z lis) | x==z = (Branch y lis) |otherwise = replaceA x y clis
replaceA :: Eq a=> a->a->[Tree a]->(Tree a) replaceA _ _ [] = Empty -- run out replaceA x y (h:r) |Q suc = suc |otherwise = replaceA x y r where suc=replace x y h
Q :: a -> Bool Q a = True Q a = False
Theres two main problems i am having. One is I'm not sure what should be the "otherwise" in the leaf function. Another problem is it doesn't show the whole tree just the part after the replacement.
If you think this is complete bull I'll quite happily start over if somebody could give me some insight into what is the best way of tackling this problem is.
Many thanks in advance
spot
-- View this message in context: http://old.nabble.com/bit-of-help-with-n-ary-please...-tp26258006p26259268.h... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.