1
這個數據類型的Foldable實例是什麼樣的?定義一個看似簡單的可摺疊實例
data X t = X t [X t]
我嘗試這樣做:
instance Foldable X where
foldMap f (X x xs) = f x `mappend` foldMap f xs
但得到這個錯誤:
Occurs check: cannot construct the infinite type: a = X a
When generalising the type(s) for `foldMap'
In the instance declaration for `Foldable X'