GHC - 类型签名中的约束无效

时间:2015-11-21 04:12:40

标签: haskell ghc type-signature

我正在尝试加载以下定义

data NestedList a = Elem a | List [NestedList a]
flatten :: (NestedList a) => a -> [a]
flatten (Elem x) = [x]

但是GHC发出错误

Expected a constraint, but 'NestedList a' has kind '*'
In the type signature for 'flatten'

类型签名中是否有遗漏或无效?

提前致谢

1 个答案:

答案 0 :(得分:1)

=>之前的部分是约束,必须包含类型类,而NestedList只是一种类型。你想写的是

flatten :: NestedList a -> [a]