[Haskell-beginners] Rose tree

mike h mike_k_houghton at yahoo.co.uk
Sun Jan 8 20:06:33 UTC 2017


I’m rapidly descending into a spiral of confusion! :)

How do I add something to a rose tree? 

I have 

data Tree a = Node a [Tree a] deriving (Show)

add :: Eq a => a -> a -> Tree a -> Tree a

and the first ‘a’ is the thing to add and the second is its parent node.
add :: Eq a => a -> a -> Tree a -> Tree a
add x px (Node x' []) = Node x' [Node x []]

I’ve tried various ways for the more general case but always seem to lose part of the tree.

Any advice would be very welcome.



More information about the Beginners mailing list