Reputation: 269
I am new at haskell and I want to instance Tree a with the class show.
data Tree a = Null
|Node (Tree a) a (Tree a)
instance Show (Tree a) where
show Null = ""
show Node ((Tree l) (v) (Tree r)) = "|"--I don´t know how i can do this step
Thanks for your help.
Upvotes: 1
Views: 4602
Reputation: 23802
Apply show
recursively:
data Tree a = Null | Node (Tree a) a (Tree a)
instance Show a => Show (Tree a) where
show Null = "Null"
show (Node l v r) = "(" ++ show l ++ " " ++ show v ++ " " ++ show r ++ ")"
Upvotes: 4