[GHC] #10524: PolyKinds doesn't interact well with DeriveFunctor

GHC ghc-devs at haskell.org
Mon Jun 15 05:01:00 UTC 2015


#10524: PolyKinds doesn't interact well with DeriveFunctor
-------------------------------------+-------------------------------------
              Reporter:              |             Owner:
  RyanGlScott                        |            Status:  new
                  Type:  bug         |         Milestone:
              Priority:  normal      |           Version:  7.10.1
             Component:  Compiler    |  Operating System:  Unknown/Multiple
              Keywords:              |   Type of failure:  GHC rejects
          Architecture:              |  valid program
  Unknown/Multiple                   |        Blocked By:
             Test Case:              |   Related Tickets:
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
 Using {{{PolyKinds}}} and {{{DeriveFunctor}}} in tandem on GHC 7.10.2-rc1
 will cause a kind incompatibility in certain cases:

 {{{
 GHCi, version 7.10.1.20150612: http://www.haskell.org/ghc/  :? for help
 λ> :set -XPolyKinds -XDeriveFunctor -ddump-deriv
 λ> newtype Compose f g a = Compose (f (g a)) deriving Functor

 ==================== Derived instances ====================
 Derived instances:
   instance forall (k_axa :: BOX)
                   (f_axb :: k_axa -> *)
                   (g_axc :: * -> k_axa).
            (GHC.Base.Functor f_axb, GHC.Base.Functor g_axc) =>
            GHC.Base.Functor (Ghci1.Compose f_axb g_axc) where
     GHC.Base.fmap f_axd (Ghci1.Compose a1_axe)
       = Ghci1.Compose (GHC.Base.fmap (GHC.Base.fmap f_axd) a1_axe)


 Generic representation:

   Generated datatypes for meta-information:

   Representation types:



 <interactive>:3:52:
     Kind incompatibility when matching types:
       f0 :: * -> *
       f :: k -> *
     Expected type: f (g b)
       Actual type: f0 (f1 b)
     Relevant bindings include
       a1 :: f (g a) (bound at <interactive>:3:52)
       fmap :: (a -> b) -> Compose f g a -> Compose f g b
         (bound at <interactive>:3:52)
     In the first argument of ‘Compose’, namely ‘fmap (fmap f) a1’
     In the expression: Compose (fmap (fmap f) a1)
     When typechecking the code for  ‘fmap’
       in a derived instance for ‘Functor (Compose f g)’:
       To see the code I am typechecking, use -ddump-deriv
 }}}

 A workaround is to use {{{StandaloneDeriving}}}:

 {{{
 λ> :set -XStandaloneDeriving
 λ> newtype Compose f g a = Compose (f (g a))
 λ> deriving instance (Functor f, Functor g) => Functor (Compose f g)

 ==================== Derived instances ====================
 Derived instances:
   instance (GHC.Base.Functor f_ayO, GHC.Base.Functor g_ayP) =>
            GHC.Base.Functor (Ghci1.Compose f_ayO g_ayP) where
     GHC.Base.fmap f_ayQ (Ghci1.Compose a1_ayR)
       = Ghci1.Compose (GHC.Base.fmap (GHC.Base.fmap f_ayQ) a1_ayR)


 Generic representation:

   Generated datatypes for meta-information:

   Representation types:
 }}}

 This problem does not seem to occur in GHC HEAD, however:

 {{{
 GHCi, version 7.11.20150608: http://www.haskell.org/ghc/  :? for help
 λ> :set -XPolyKinds -XDeriveFunctor -ddump-deriv
 λ> newtype Compose f g a = Compose (f (g a)) deriving Functor

 ==================== Derived instances ====================
 Derived instances:
   instance forall (k_a148 :: BOX)
                   (f_a149 :: k_a148 -> *)
                   (g_a14a :: * -> k_a148).
            (GHC.Base.Functor f_a149, GHC.Base.Functor g_a14a) =>
            GHC.Base.Functor (Ghci3.Compose f_a149 g_a14a) where
     GHC.Base.fmap f_a14b (Ghci3.Compose a1_a14c)
       = Ghci3.Compose (GHC.Base.fmap (GHC.Base.fmap f_a14b) a1_a14c)


 Generic representation:

   Generated datatypes for meta-information:

   Representation types:
 }}}

 Can this fix be backported in time for GHC 7.10.2?

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


More information about the ghc-tickets mailing list