
Hi folks, I'm working on a program that I've been dabbling with for years. For the first time, I tried to compile it with GHC 6.6, and got an error, explaining that I was violating the Coverage Condition in my instance declaration. The instance declaration looks like this: instance MonadReader r m => MonadReader r (CPST o m) where ... The MonadReader class definition, which doesn't appear to have changed since 6.4.2, looks like this: class Monad m => MonadReader r m | m -> r where ... Apparently, the Coverage Condition disallows my instance declaration, because the variable 'r' is not mentioned in the '(CPST o m)' term. Now this would make sense to me if I didn't have the assertion 'MonadReader r m'. Because of that assertion, m -> r, so '(CPST o m)' shouldn't need to explicitly mention 'r'. I will try using -fallow-undecidable-instances, and see if the message goes away. But can someone explain to me why this is wrong, and what would be the preferred way to write it? I've attached the two relevant source files. (Try compiling both files.) Thanks, Lyle

On Tue, Dec 26, 2006 at 07:01:52PM -0500, lists@qseep.net wrote:
I'm working on a program that I've been dabbling with for years. For the first time, I tried to compile it with GHC 6.6, and got an error, explaining that I was violating the Coverage Condition in my instance declaration. The instance declaration looks like this:
instance MonadReader r m => MonadReader r (CPST o m) where ...
1. Does 'CPS' stand for Continuation Passing Style? If so, have a look at Control.Monad.Cont.ContT and eliminate your problem entirely (free pre-debugged code) 2. Your problem, is that *looking only at the instance head*, r could be anything. GHC doesn't look at the context when deciding wether an instance is compatible with functional dependencies. 3. http://darcs.haskell.org/packages/mtl/Control/Monad/Cont.hs Looking at the standard CPS monad, there is a {-# OPTIONS_GHC -fallow- undecidable-instances #-} pragma and a comment to the effect of it being required for the MonadReader instance.

On Tue, Dec 26, 2006 at 07:01:52PM -0500, lists@qseep.net wrote:
I'm working on a program that I've been dabbling with for years. For the first time, I tried to compile it with GHC 6.6, and got an error, explaining that I was violating the Coverage Condition in my instance declaration. The instance declaration looks like this:
instance MonadReader r m => MonadReader r (CPST o m) where ...
1. Does 'CPS' stand for Continuation Passing Style? If so, have a look at Control.Monad.Cont.ContT and eliminate your problem entirely (free pre-debugged code)
Thanks, I'm aware of that module. I'm rolling my own on purpose. The supplied ContT doesn't support 'shift', only 'callCC'. Also, The standard monad overly restricts the type of 'callCC', so that the captured continuation can only be used in a single type context. My 'shift' and 'callCC' are rank-3 polymorphic, which permits them to be used in more contexts.
2. Your problem, is that *looking only at the instance head*, r could be anything. GHC doesn't look at the context when deciding wether an instance is compatible with functional dependencies.
Yes, I think that is the problem.
3. http://darcs.haskell.org/packages/mtl/Control/Monad/Cont.hs Looking at the standard CPS monad, there is a {-# OPTIONS_GHC -fallow- undecidable-instances #-} pragma and a comment to the effect of it being required for the MonadReader instance.
That's what I ended up adding to mine, as well, and it works now. Thanks. I guess GHC is just being overly cautious. Regards, Lyle

GHC is simply being more conservative. GHC 6.4.2 was straying too close to non-termination, as our paper shows: http://research.microsoft.com/~simonpj/papers/fd-chr Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe- | bounces@haskell.org] On Behalf Of lists@qseep.net | Sent: 27 December 2006 00:02 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] Coverage Condition? | | Hi folks, | | I'm working on a program that I've been dabbling with for years. For | the first time, I tried to compile it with GHC 6.6, and got an error, | explaining that I was violating the Coverage Condition in my instance | declaration. The instance declaration looks like this: | | instance MonadReader r m => MonadReader r (CPST o m) where ... | | The MonadReader class definition, which doesn't appear to have changed | since 6.4.2, looks like this: | | class Monad m => MonadReader r m | m -> r where ... | | Apparently, the Coverage Condition disallows my instance declaration, | because the variable 'r' is not mentioned in the '(CPST o m)' term. Now | this would make sense to me if I didn't have the assertion 'MonadReader | r m'. Because of that assertion, m -> r, so '(CPST o m)' shouldn't need | to explicitly mention 'r'. | | I will try using -fallow-undecidable-instances, and see if the message | goes away. But can someone explain to me why this is wrong, and what | would be the preferred way to write it? I've attached the two relevant | source files. (Try compiling both files.) | | Thanks, | Lyle
participants (3)
-
lists@qseep.net
-
Simon Peyton-Jones
-
Stefan O'Rear