GHC - 类型签名中的约束无效
GHC - constraint in type signature invalid
我正在尝试加载以下定义
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'
类型签名中是否缺少或无效?
提前致谢
=>
之前的部分是一个约束,必须包含类型类,而NestedList
只是一个类型。你想写的是
flatten :: NestedList a -> [a]
我正在尝试加载以下定义
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'
类型签名中是否缺少或无效?
提前致谢
=>
之前的部分是一个约束,必须包含类型类,而NestedList
只是一个类型。你想写的是
flatten :: NestedList a -> [a]