[GHC] #11450: Associated types at wrong type in instance

GHC ghc-devs at haskell.org
Thu Jan 21 15:41:32 UTC 2016


#11450: Associated types at wrong type in instance
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  7.10.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Replying to [comment:8 simonpj]:
 > It's simple. Consider
 > {{{
 > class C v where
 >   type T a b v cd
 > }}}
 > In any instance declaration, the type in the `v` position of the `type`
 instance must be the same as in the instance header:
 > {{{
 > instance ... => C ty where
 >   type T p q ty r s = <rhs>
 > }}}
 > I think we do (or at least should) also insist that `p`, `q`, `r`, `s`
 are distinct type variables, otherwise the type instance is more specific
 than the class instance, but that's a separate matter.

 Thank you for a formal description of what's going on, but I'm still
 confused about how this should behave w.r.t. wildcards. By the above
 rules, if you have

 {{{#!hs
 class Warning a where
   type T a

 instance Warning (Either a b) where
   ...
 }}}

 Then we'd have to do something like this:

 {{{#!hs
 instance Warning (Either a b) where
   type T (Either a b) = a
 }}}

 But this results in a warning on GHC 8.0!

 {{{
     Defined but not used: type variable ‘b’
 }}}

 And if you changed `b` to `_`, it would no longer follow the rules
 described above.

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


More information about the ghc-tickets mailing list