[GHC] #14331: Overzealous free-floating kind check causes deriving clause to be rejected

GHC ghc-devs at haskell.org
Sat Oct 14 00:08:16 UTC 2017


#14331: Overzealous free-floating kind check causes deriving clause to be rejected
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  merge
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler (Type    |              Version:  8.2.1
  checker)                           |
      Resolution:                    |             Keywords:  deriving
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  GHC rejects       |            Test Case:
  valid program                      |  deriving/should_compile/T14331
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 You're right, that should work out in the end. Thank you for the patient
 explanation, and sorry for being slow on the uptake.

 Replying to [comment:20 goldfire]:
 > However, in writing this up, I discovered a new problem. When I write
 >
 > {{{#!hs
 > class C2 a
 > data D b = D deriving C2
 > }}}
 >
 > do I mean
 >
 > {{{#!hs
 > instance C2 {k -> Type} D
 > }}}
 >
 > or
 >
 > {{{#!hs
 > instance C2 {Type} (D b)
 > }}}
 >
 > ? Both are well-kinded and sensible. Right now, we always choose the
 latter, but I'm not sure why.

 The usual convention for figuring out how many type variables to eta
 reduce from the datatype is to simply count the number of argument types
 in the kind `k` in `deriving (Cls c1 ... cn :: k -> Constraint)`. In this
 example, the kind is just a plain kind variable, which we count as having
 zero arguments. Thus, we don't eta reduce any type variables, resulting in
 the latter instance.

 This convention doesn't bother me that much, since if the user wanted to
 derive `instance C2 D`, they could just as well write `data D a = D
 deriving (C2 :: (k -> Type) -> Constraint)`.

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


More information about the ghc-tickets mailing list