简体   繁体   English

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

[英]GHC - constraint in type signature invalid

I'm trying to load the following definition 我正在尝试加载以下定义

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

But GHC is giving an error 但是GHC给出了一个错误

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

Is there something missing or invalid in the type signature? 类型签名中是否缺少或无效的东西?

Thanks in advance 提前致谢

The part before => is a constraint and must contain type classes, while NestedList is just a type. =>之前的部分是一个约束,必须包含类型类,而NestedList只是一个类型。 What you wanted to write is 你想写的是

flatten :: NestedList a -> [a]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM