Data.Functor.Compose:
newtype Compose f g a = Compose { getCompose :: f (g a) }
there's clear-cut, more traditional instances if `f` and `g` are Applicative:
instance (Applicative f, Applicative g, Semigroup a) => Semigroup (Compose f g a) where
(<>) = liftA2 (<>)
instance (Applicative f, Applicative g, Monoid a) => Monoid (Compose f g a) where
mempty = pure mempty
There's an alternative with `QuantifiedConstraints`, but it's arguable that this is desirable:
instance (forall x. Semigroup x => Semigroup (f x), forall x. Semigroup x => Semigroup (g x), Semigroup a) => Semigroup (Compose f g a) where
Compose x <> Compose y = Compose (x <> y)
Both to seem to fit the commonplace spirit of lifting monoids up through applicative contexts.