0
我的樹可摺疊和樹
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]
怎麼辦我在類型樹a的實例聲明中使用t而不是?