[GHC] #14243: GHC doesn't add constraint when deriving

GHC ghc-devs at haskell.org
Sat Sep 16 22:46:58 UTC 2017


#14243: GHC doesn't add constraint when deriving
-------------------------------------+-------------------------------------
           Reporter:  Iceland_jack   |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 I can't remember if this was intended, but GHC cannot `derive newtype
 Functor` or `derive stock Functor` for `WGeneric` even if it knows the
 constraint to add (I have `FlexibleInstances` enabled)

 {{{#!hs
 import GHC.Generic

 -- • Could not deduce (Functor (Rep1 f))
 --     arising from the 'deriving' clause of a data type declaration
 --   from the context: Functor f
 --     bound by the deriving clause for ‘Functor (WGeneric f)’
 --     at /home/baldur/hs/074.hs:63:5-11
 --   Possible fix:
 --     use a standalone 'deriving instance' declaration,
 --       so you can specify the instance context yourself
 newtype WGeneric f a = WGeneric (Sum (Rep1 f) f a)
   deriving newtype
     Functor
 }}}

 but either of these works

 {{{#!hs
 deriving newtype instance (Functor f, Functor (Rep1 f)) => Functor
 (WGeneric f)

 deriving stock   instance (Functor f, Functor (Rep1 f)) => Functor
 (WGeneric f)
 }}}

 Could GHC add the inferred `Functor (Rep1 f)`?

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


More information about the ghc-tickets mailing list