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

GHC ghc-devs at haskell.org
Tue Apr 19 07:52:26 UTC 2016


#11450: Associated types at wrong type in instance
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:
            Type:  bug               |               Status:  closed
        Priority:  high              |            Milestone:  8.0.2
       Component:  Compiler          |              Version:  7.10.3
      Resolution:  fixed             |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  GHC accepts       |            Test Case:  indexed-
  invalid program                    |  types/should_fail/T11450
      Blocked By:                    |             Blocking:
 Related Tickets:  #11449, #11451    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by simonpj):

 * status:  new => closed
 * testcase:   => indexed-types/should_fail/T11450
 * resolution:   => fixed


Comment:

 OK I've finally dealt with this one.

 I decided to tighten the rules, so that a `type instance` for an
 associated type, nested in a class `instance` declaration, must have an
 LHS that precisely matches the template laid out in the `class`
 declaration:

 * The arg positions that correspond to class type variables must be
 exactly as in the instance header

 * The other arg positions must be distinct type variables.

 That means you can no longer give ''multiple'' `type instance` decls for
 the same associated type in one `instance` decl.  For example:
 {{{
 class C a where
   type F a b

 instance C Int where
   type F Int Bool = Char
   type F Int Char = Bool
 }}}
 This is now illegal: the second arg position must be a variable.  It's
 pretty weird anyway because the second arg position is open, so matching
 is incomplete.  If you want something like that, use an auxiliary
 definition:
 {{{
 instance C Int where
   type F Int b = FInt b

 type family FInt b
 type instance FInt Bool = Char
 type instance FInt Char = BOol
 }}}
 If the second arg is a closed type, you can use a closed type family
 definition, even better.

 This is a behaviour change -- but it's onle that the user manual
 explicitly signaled as subject to change.

 Don't merge to 8.0.

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


More information about the ghc-tickets mailing list