我正在尝试加载以下定义
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'
类型签名中是否有遗漏或无效?
提前致谢
答案 0 :(得分:1)
=>
之前的部分是约束,必须包含类型类,而NestedList
只是一种类型。你想写的是
flatten :: NestedList a -> [a]