我是haskell的新手,我希望用类show实例Tree a。
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
感谢您的帮助。
答案 0 :(得分:4)
递归申请show
:
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 ++ ")"