实例显示树数据结构

时间:2012-12-02 14:10:23

标签: haskell

我是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

感谢您的帮助。

1 个答案:

答案 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 ++ ")"