1

私はhaskellを初めて使用し、クラスショーでTreeaをインスタンス化したいと思います。

  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 に答える