Monoid Instance for `a -> b` I attempted to implement a Monoid' instance for a function a -&gt; b.

class Monoid' a where
    mempty  :: a -&gt; a
    mappend :: a -&gt; a -&gt; a

instance Monoid' (a -&gt; b) where
    mempty  f   = f
    mappend f g = g . f


Please critique it for correctness and style.

In addition, I'm curious how mappend should be implemented. Should f or g be applied first?
Something nice about hackage help/documentation pages like the one you linked: you can go straight to the source code by clicking on the links on the right side of the page.  Looking at the source, there is an instance for Monoid b =&gt; Monoid (a -&gt; b), which is not quite exactly what you're trying to do, since it restricts b to types with a Monoid implementation.  It uses a nice trick where it implements this monoid in terms of the other monoid.  

The Data.Monoid code:

instance Monoid b =&gt; Monoid (a -&gt; b) where
    mempty _ = mempty
    mappend f g x = f x `mappend` g x


If you have any difficulty understanding it, keep in mind that the mempty and mappend functions are for different monoids on the left hand side than they are for the right hand side.  

I can think of 2 ways of getting 2 a -&gt; bs to combine: throw away the first one, or throw away the second one.  Neither seems similar to what you're trying to do (or particularly useful).  

Besides the (already noted) problem that . as an implementation of mappend won't typecheck, there's another problem: mempty.  As written, it'll typecheck, but the type signature of your mempty is a -&gt; a, while it should be just a.  mempty is a value in the monoid.  

I'd be tempted to change the definition to mempty = id, but id :: a -&gt; a not a -&gt; b.  You could try to make a constant function that just returns some particular b, but since you have no idea what type b will be, that's not possible.  

In general, haskell's type system is very nice -- not only can it catch type errors, but it can serve as documentation, provide a bit of heuristic guidance and help you organize your thoughts.  When something doesn't typecheck, it means what you're trying to do doesn't quite make sense.