[GHC] #10831: DeriveFunctor not capable of deriving when wrapping Either

GHC ghc-devs at haskell.org
Tue Sep 8 07:48:05 UTC 2015


#10831: DeriveFunctor not capable of deriving when wrapping Either
-------------------------------------+-------------------------------------
        Reporter:  htebalaka         |                   Owner:
            Type:  bug               |                  Status:  new
        Priority:  low               |               Milestone:
       Component:  Compiler (Type    |                 Version:  7.10.2
  checker)                           |
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------
Changes (by thomie):

 * os:  MacOS X => Unknown/Multiple
 * component:  Compiler => Compiler (Type checker)


Old description:

> GHC can derive Functor for Okay, but rejects the equivalent Bad.
> {{{#!hs
> {-# LANGUAGE DeriveFunctor #-}
> data Okay f g a b = Inl (f a b) | Inr (g a b) deriving (Functor)
> newtype Bad f g a b = Bad (Either (f a b) (g a b)) deriving (Functor)
> }}}

New description:

 GHC can derive Functor for Okay, but rejects the equivalent Bad.
 {{{#!hs
 {-# LANGUAGE DeriveFunctor #-}
 data Okay f g a b = Inl (f a b) | Inr (g a b) deriving (Functor)
 newtype Bad f g a b = Bad (Either (f a b) (g a b)) deriving (Functor)
 }}}
 {{{
     Can't make a derived instance of ‘Functor (Bad f g a)’:
       Constructor ‘Bad’ must use the type variable only as the last
 argument of a data type
     In the data declaration for ‘Bad’

 }}}

--

Comment:

 This comment (option `c`) in `compiler/typecheck/TcDeriv.hs` says this is
 to be expected:
 {{{
  cond_functorOK :: Bool -> Bool -> Condition
  -- OK for Functor/Foldable/Traversable class
  -- Currently: (a) at least one argument
  --            (b) don't use argument contravariantly
  --            (c) don't use argument in the wrong place, e.g. data T a =
 T (X a a)
  --            (d) optionally: don't use function types
  --            (e) no "stupid context" on data type
 }}}

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


More information about the ghc-tickets mailing list