Compiling this short snippet on GHC 8.6.2:
{-# LANGUAGE DeriveGeneric, PolyKinds #-}
import GHC.Generics
data Foo f
= FA
| FB (f (Foo f))
deriving (Generic, Generic1)
Results in this error:
Can't make a derived instance of ‘Generic1 Foo’:
Constructor ‘FB’ applies a type to an argument involving the last parameter
but the applied type is not of kind * -> *
Is it not possible to derive Generic for such types? Why?
Generic1 Foocan't be derived becauseGeneric1is meant for types of kind* -> *, not(* -> *) -> *. In principle there could be support for(* -> *) -> *with more constructors inGHC.Generics, but this approach just doesn't scale well (it comes with lots more unintuitive syntactic restrictions, and you will always have the same problem for more complex types).You can actually do a lot with plain
Genericthat overlaps with the initially intended use cases forGeneric1. Otherwise, you'll need something more powerful thanGHC.Genericslike, perhaps, the recently released kind-generics (includes links to paper and hackage).