Skip to content

DeriveFunctor spuriously rejects existential context with type synonym mentioning the last type variable

This code does not compile:

{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE StandaloneDeriving #-}
module Bug where

import GHC.Exts (Constraint)

type C (a :: Constraint) b = a

data T a b = C (Show a) b => MkT b
deriving instance Functor (T a)
GHCi, version 8.2.0.20170523: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )

Bug.hs:13:1: error:
    • Can't make a derived instance of ‘Functor (T a)’:
        Constructor ‘MkT’ must be truly polymorphic in the last argument of the data type
    • In the stand-alone deriving instance for ‘Functor (T a)’
   |
13 | deriving instance Functor (T a)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But it should, since if you expand C (Show a) b, you're left with Show a, which doesn't mention the last type variable b at all.

Fix incoming.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information