尝试使用以下代码为数据树创建可折叠实例:
data Rose a = a :> [Rose a]
deriving (Eq, Show)
instance Foldable Rose where
fold (a:>b) = a <> (map fold b)
但是此代码不起作用,它产生的错误:
Could not deduce <m ~ [m]>
from the context <Monoid m>
bount by the type signature for fold :: Monoid m => Rose m -> m
...
In the return type of a call of 'map'
...
有谁知道为什么/如何使它工作?