#4485: Unexplained change in type-inference + OverlappingInstances in
---------------------------------+------------------------------------------
    Reporter:  JeremyShaw        |        Owner:                           
        Type:  bug               |       Status:  new                      
    Priority:  normal            |    Milestone:                           
   Component:  Compiler          |      Version:  7.0.1 RC1                
    Keywords:                    |     Testcase:                           
   Blockedby:                    |   Difficulty:                           
          Os:  Unknown/Multiple  |     Blocking:                           
Architecture:  Unknown/Multiple  |      Failure:  GHC rejects valid program
---------------------------------+------------------------------------------

Comment(by simonpj):

 Thanks for the example.  GHC 7 isn't behaving well here, but 6.12 may be
 behaving even worse.

 Look at the typing problem that arises from
 {{{
 instance EmbedAsChild (IdentityT IO) FooBar where
    asChild b = asChild $ (genElement "foo")
 }}}
 After a bit of figuring, you should see that we have to solve the
 following type constraints:
 {{{
      EmbedAsChild (IdentityT IO) (XMLGen meta (XML meta)
      XMLGen meta
 }}}
 where `meta` is an unknown unification variable arising from instantiating
 the call to `genElement :: `XMLGen m => String -> XMLGenT m (XML m)`.

 There are no other constraints on `meta`.  OK, so now how is GHC supposed
 to figure out what `meta` is?  Well, there are four instance declarations
 (each with a different context, but that doesn't matter here):
 {{{
     EmbedAsChild (IdentityT IO) FooBar
     EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
     EmbedAsChild m              (XMLGenT m1 c)
     EmbedAsChild m              x
 }}}
 Remember, we have to match without knowing what `meta` is going to turn
 out to be.  The first cannot match, but the latter three in principle
 could, depending on how `meta` is eventually instantiated.  The fourth is
 ignored becuase the third is more specific.

 So there you are: we don't know which one to pick.  In GHC 7 the error
 message is wrong, because it only mentions one of the two.

 I'm honestly not sure why 6.12 accepts this.

 So: what is your reasoning that says `meta` cannot instantite to
 `Identity`.  Maybe you reason that `XML Identity` does not reduce to `()`,
 but that is very fragile.  You might add such an instance declaration. And
 in any case it's beyond GHC's instance-matching powers to figure that out.

 But perhaps you have an intutition in mind?

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4485#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to