无法为此类型派生泛型?

Can't derive Generic for this type?

在 GHC 8.6.2 上编译这个简短的片段:

{-# LANGUAGE DeriveGeneric, PolyKinds #-}
import GHC.Generics

data Foo f
    = FA
    | FB (f (Foo f))
    deriving (Generic, Generic1)

导致此错误:

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 * -> *

是否无法为此类类型派生 Generic?为什么?

Generic1 Foo 无法派生,因为 Generic1 是针对类型 * -> * 而不是 (* -> *) -> * 的类型。原则上,在 GHC.Generics 中可以支持具有更多构造函数的 (* -> *) -> *,但这种方法不能很好地扩展(它带有更多不直观的句法限制,而且你总是会遇到同样的问题更复杂的类型)。

您实际上可以使用与 Generic1 的最初预期用例重叠的普通 Generic 做很多事情。否则,您将需要比 GHC.Generics 更强大的东西,比如最近发布的 kind-generics(包括指向论文和 hackage 的链接)。