title: Writing a foldMap in Haskell
body: <p>I am trying to write my own foldMap function as an excersice to learn Haskell</p>
  
  <p>Currently it looks like this</p>
  
  <pre><code>class Functor f =&gt; Foldable f where
      fold    :: Monoid m =&gt;             f m -&gt; m
      foldMap :: Monoid m =&gt; (a -&gt; m) -&gt; f a -&gt; m
      foldMap g a = fold (&lt;&gt;) mempty (fmap g a)
  </code></pre>
  
  <p>However when compiling it it gives the following error</p>
  
  <pre><code>Could not deduce (Monoid ((f m -&gt; m) -&gt; fm -&gt; 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 =&gt; (a -&gt; m) -&gt; f a -&gt; m at (file location
  In the expression fold (&lt;&gt;) mempty (fmap g a)
  In an equation for 'foldMap':
       foldMap g a = fold (&lt;&gt;) mempty (fmap g a)
  </code></pre>
  
  <p>I can't figure out what the compiler is trying to tell me with this error, can anyone tell me what goes wrong with my foldMap?  </p>