1

我是 haskell 的新手,我想在课堂表演中实例化 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

谢谢你的帮助。

4

1 回答 1

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 ++ ")"
于 2012-12-02T14:21:18.680 回答