5
試圖讓一個可摺疊的實例用下面的代碼數據樹:數據樹哈斯克爾可摺疊例如
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'
...
有誰知道爲什麼/如何使其工作?
«不工作»是沒有用的。它不是typecheck?那麼錯誤信息是什麼?或者它產生了錯誤的結果?在什麼輸入? –
編輯我的帖子與我得到的錯誤消息 – Skyfe
你明白什麼錯誤信息說?如果你慢慢閱讀,我敢打賭你會知道如何解決你的問題。如果不是,你也應該說出你不明白哪部分錯誤。 –