4

在 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不能为这种类型派生吗?为什么?

4

1 回答 1

7

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

实际上,您可以Generic使用与Generic1. 否则,您GHC.Generics可能需要比最近发布的kind-generics更强大的东西(包括论文和 hackage 的链接)。

于 2018-11-27T11:53:22.237 回答