#5248: Infer type context in a type signature
----------------------------------------+-----------------------------------
    Reporter:  gidyn                    |        Owner:                         
  
        Type:  feature request          |       Status:  new                    
  
    Priority:  normal                   |    Milestone:                         
  
   Component:  Compiler (Type checker)  |      Version:  7.0.3                  
  
    Keywords:                           |     Testcase:                         
  
   Blockedby:                           |   Difficulty:                         
  
          Os:  Unknown/Multiple         |     Blocking:                         
  
Architecture:  Unknown/Multiple         |      Failure:  GHC rejects valid 
program
----------------------------------------+-----------------------------------

Comment(by simonpj):

 Replying to [comment:4 gidyn]:

 > This example doesn't ''require'' the C a => constraint, but it's
 certainly there for practical purposes; you can't get a Bar without it.

 I don't know what you mean by "for practical purposes".  Yes you need (Bar
 a), but it's supplied by the pattern match on Bar.  So it's not needed on
 the instance, and absolutely should not be. Try it!

 > This would be different to normal type inference. Instead of inferring
 the type context required by an equation, the data type (or constructor)
 itself carries a type context, which is there whether or not it's needed.
 For example, your instance C (Bar a) would have a C a => type context. Not
 because the instance declaration requires it (it doesn't), but because Bar
 implies it.

 No. What constraint is required depends on what type `Bar` (or `bar`) are
 applied at.  If you apply them at `Int` you'll need `C Int`; if you apply
 them at `[a]` you'll need `C [a]`, and so on.

 > That Bar a implies C a => is something that we know to be true in any
 case, but the compiler currently discards this information.

 I don't know what you mean by "know to be true". If you add an unnecessary
 context to an instance declaration, you'll make some programs fail that
 previously would type check.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5248#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to