Skip to content

Surprising error message when deriving Functor for a GADT

{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}

data T a b where
    Mk :: Int -> b -> T Int b
    deriving (Functor)

GHC says:

    Can't make a derived instance of ‘Functor (T a)’:
      Constructor ‘Mk’ has existentials or constraints in its type
      Possible fix: use a standalone deriving declaration instead
    In the data declaration for ‘T’

This is not true - Mk does not existentially quantify anything, nor does it have a constraint in its type. The suggested fix of using a standalone deriving declaration works though. I'm guessing GHC is turning my declaration into Mk :: (a ~ Int) => a -> b -> T a b?

Tested on 7.10.3 running in OSX Mavericks.

Edited by benjamin.hodgson
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information