我对树有以下定义
data Tree a = Leaf a
| Node [Tree a]
deriving (Show)
以下是可折叠的实例:
instance Foldable (Tree) where
foldMap f (Leaf t) = (f t)
foldMap f (Node t) = (foldMap `mappend` (foldMap f) t)
这段代码抛出了我和错误
Couldn't match type `a' with `Tree a'
`a' is a rigid type variable bound by
the type signature for
foldMap :: Monoid m => (a -> m) -> Tree a -> m
at trees.hs:8:5
Expected type: [a]
Actual type: [Tree a]
如何在 Tree a 类型的实例声明中使用 t 而不是 a?