Reduction stack overflow

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 hence Monad (m [Foo]) and hence Applicative (m [Foo])), if only it can solve Monoid [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 solve Monoid [Foo] again, and the loop begins.

GHC really ought to at least require UndecidableInstances for this, but currently it fails to do so:

6 Likes