[Haskell] MTL violates coverage condition?

Mike Haskel mlh2131 at columbia.edu
Tue Nov 20 04:30:27 EST 2007


A bit of a detailed technical question.

I'm writing a library which makes heavy use of the MTL (Monad.State,
etc) and monad transformers.  I have a monad transformer, MymonadT,
which I want to inherit relevant type classes from the monads it
transforms, i.e.

MonadState s m => MonadState s (MymonadT m).

The MTL itself uses such instance declarations, such as

MonadState s m => MonadState s (ReaderT r m).

When I compile my library however (using ghc-6.6.1 and
-fglasgow-exts) I get an illegal instance declaration error:
  "The Coverage Condition fails for one of the functional dependencies;
   Use -fallow-undecidable-instances to permit this."
The code compiles with -fallow-undecidable-instances.

As a reminder, MonadState is declared as

class Monad m => MonadState s m | m -> s

The coverage condition is described in
http://research.microsoft.com/~simonpj/papers/fd-chr/jfp06.pdf on page
12.  My own analysis suggests that the declaration of MonadState for
ReaderT violates this condition as well.

The coverage condition exists, this paper claims, to prevent infinite
loops in type inference---someone could use some instance declarations
violating this condition to write a function whose type is

Does 'MonadState s m => MonadState s (ReaderT r m)', found in
Control.Monad.Reader violate the coverage condition as I believe it

Can one write a function using this library to force the type
inference engine to loop indefinitely?  If not, what mitigating
conditions prevent it?  Can I write a similar declaration in my
library and compile it with -fallow-undecidable-instances and without


More information about the Haskell mailing list