Skip to content

Regression when deriving Generic1 on poly-kinded data family

On GHC 7.10.3, the following code compiles:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
module ProxyFam where

import GHC.Generics (Generic1)

data family   ProxyFam (a :: k)
data instance ProxyFam (a :: k) = ProxyCon deriving Generic1

But on GHC 8.1, it fails:

$ /opt/ghc/head/bin/ghc ProxyFam.hs 
[1 of 1] Compiling ProxyFam         ( ProxyFam.hs, ProxyFam.o )

ProxyFam.hs:10:53: error:
    • Can't make a derived instance of ‘Generic1 ProxyFam’:
        ProxyFam must not be instantiated; try deriving `ProxyFam k a' instead
    • In the data instance declaration for ‘ProxyFam’

I'm not sure what exactly is going on here, but I have a hunch. The Generic1 typeclass is of kind * -> *, which means that in a Generic1 ProxyFam instance, the kind of a is instantiated to *.

Curiously, though, the same error does not appear when deriving Generic for a normal datatype (e.g., data ProxyFam (a :: k) = ProxyCon deriving Generic1).

Richard, I'm stuck as to how to fix this. I suspect this was triggered by -XTypeInType-related changes, specifically, this change:

diff --git a/compiler/typecheck/TcGenGenerics.hs b/compiler/typecheck/TcGenGenerics.hs
index 2c5b80e..fb18517 100644 (file)
--- a/compiler/typecheck/TcGenGenerics.hs
+++ b/compiler/typecheck/TcGenGenerics.hs
@@ -147,7 +146,7 @@ canDoGenerics tc tc_args
           --
           -- Data family indices can be instantiated; the `tc_args` here are
           -- the representation tycon args
-              (if (all isTyVarTy (filterOut isKind tc_args))
+              (if (all isTyVarTy (filterOutInvisibleTypes tc tc_args))
                 then IsValid
                 else NotValid (tc_name <+> text "must not be instantiated;" <+>
                                text "try deriving `" <> tc_name <+> tc_tys <>

What exactly does filterOutInvisibleTypes do?

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