Haskell を学ぶための演習として、独自の foldMap 関数を作成しようとしています。
現在はこんな感じ
class Functor f => Foldable f where
fold :: Monoid m => f m -> m
foldMap :: Monoid m => (a -> m) -> f a -> m
foldMap g a = fold (<>) mempty (fmap g a)
ただし、コンパイルすると、次のエラーが発生します
Could not deduce (Monoid ((f m -> m) -> fm -> m)) arising from use of 'fold'
from the context (Foldable f) bound by the class declaration for 'Foldable' at (file location)
or from (Monoid m) bound by the type signature for foldMap :: Monoid m => (a -> m) -> f a -> m at (file location
In the expression fold (<>) mempty (fmap g a)
In an equation for 'foldMap':
foldMap g a = fold (<>) mempty (fmap g a)
このエラーでコンパイラが何を伝えようとしているのかわかりません。foldMap の何が問題なのか誰か教えてもらえますか?