
Hello glasgow-haskell-users, attached module compiles fine with ghc 6.4.2, hugs 2003+, but not with my ghc 6.5 snapshot. it says: 66.hs:9:0: Illegal instance declaration for `Stream m (StringReader r)' (the Coverage Condition fails for one of the functional dependencies) In the instance declaration for `Stream m (StringReader r)' -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Quite right; that's just as specified. The coverage condition is documented in the manual. (GHC 6.4 and Hugs are too liberal, and thereby risk divergence during type checking.) If you want this program to work, use -fallow-undecidable-instances Simon | -----Original Message----- | From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users- | bounces@haskell.org] On Behalf Of Bulat Ziganshin | Sent: 20 September 2006 14:14 | To: glasgow-haskell-users@haskell.org | Subject: 6.6 strikes me again :) | | Hello glasgow-haskell-users, | | attached module compiles fine with ghc 6.4.2, hugs 2003+, but not with | my ghc 6.5 snapshot. it says: | | 66.hs:9:0: | Illegal instance declaration for `Stream m (StringReader r)' | (the Coverage Condition fails for one of the functional dependencies) | In the instance declaration for `Stream m (StringReader r)' | | -- | Best regards, | Bulat mailto:Bulat.Ziganshin@gmail.com

Hello Simon, Wednesday, September 20, 2006, 7:35:39 PM, you wrote:
Quite right; that's just as specified. The coverage condition is documented in the manual. (GHC 6.4 and Hugs are too liberal, and thereby risk divergence during type checking.) If you want this program to work, use -fallow-undecidable-instances
let's look at the slightly modified program: class (Monad m) => MRef m r | r->m, m->r class (Monad m) => Stream m h | h->m newtype StringReader r = StringReader r instance (Monad m, MRef m r) => Stream m (StringReader r) coverage condition requires that monad type 'm' should occur in stream handle type 'StringReader r'. With MRef defined as bijective type function between m and r that is, in fact, true. may be compiler is just not smart enough to figure this? is using -fallow-undecidable-instances safe in this situation? what of MRef fundeps, r->m or m->r, is really necessary in this case - i think it is r->m ? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

| class (Monad m) => MRef m r | r->m, m->r | class (Monad m) => Stream m h | h->m | newtype StringReader r = StringReader r | instance (Monad m, MRef m r) => Stream m (StringReader r) | | coverage condition requires that monad type 'm' should occur in stream | handle type 'StringReader r'. With MRef defined as bijective type | function between m and r that is, in fact, true. may be compiler is just not smart | enough to figure this? The coverage condition is certainly conservative -- there are cases where nothing goes wrong if you drop it, and that's what -fallow-undecidable-instances does. The worst that can happen with -fallow-undecidable-instances is that the type checker loops (and even then it'll usually emit an error message); if the program typechecks it'll run ok. | is using -fallow-undecidable-instances safe in this situation? | what of MRef fundeps, r->m or m->r, is really necessary in this case - | i think it is r->m ? I think you are right. You could also try adding 'm' as a phantom type parameter to StringrReader. Simon
participants (2)
-
Bulat Ziganshin
-
Simon Peyton-Jones