I think this program indeed yields an infinite loop in the constraint solver. The issue is that MonadWriter e (m e) has Monoid e as a superclass, so when GHC tries to solve the Applicative (m [Foo]) constraint arising from pure:
- It can use the quantified constraint to get
MonadWriter [Foo] (m [Foo])(and henceMonad (m [Foo])and henceApplicative (m [Foo])), if only it can solveMonoid [Foo]. - Now in order to produce
Monoid [Foo], rather than using the global instance, it foolishly decides to use the quantified constraint and take the superclass. But then it needs to solveMonoid [Foo]again, and the loop begins.
GHC really ought to at least require UndecidableInstances for this, but currently it fails to do so: