这个纯脚本构造函数有什么问题?
What's wrong with this purescript constructor?
正在尝试为罗马数字创建构造函数:
data RomanDigit a = M | D | C | L | V | I
newRomanDigit :: Int -> RomanDigit
newRomanDigit 1000 = M
newRomanDigit 500 = D
收到错误消息:
in module UserMod
at src\UserMod.purs line 81, column 1 - line 81, column 35
Could not match kind
Type
with kind
Type -> Type
while checking the kind of Int -> RomanDigit
in value declaration newRomanDigit
我做错了什么?
您为 RomanDigit
提供了一个类型参数 a
,但尚未在 newRomanDigit
的声明中为其指定值。
您声明它的方式,RomanDigit
不是 Type
。 RomanDigit Int
是一个 Type
,或者 RomanDigit String
是一个 Type
,或者 RomanDigit (Array Boolean)
是一个 Type
,但 RomanDigit
本身不是 Type
,因为它缺少声明的类型参数 a
。这就是编译器告诉你的。
您需要删除该参数,例如:
data RomanDigit = M | D | C | L | V | I
或在使用RomanDigit
时指定,例如:
newRomanDigit :: Int -> RomanDigit Int
由于参数不存在于任何值中,我怀疑您并不是真的有意将它放在那里。
正在尝试为罗马数字创建构造函数:
data RomanDigit a = M | D | C | L | V | I
newRomanDigit :: Int -> RomanDigit
newRomanDigit 1000 = M
newRomanDigit 500 = D
收到错误消息:
in module UserMod
at src\UserMod.purs line 81, column 1 - line 81, column 35
Could not match kind
Type
with kind
Type -> Type
while checking the kind of Int -> RomanDigit
in value declaration newRomanDigit
我做错了什么?
您为 RomanDigit
提供了一个类型参数 a
,但尚未在 newRomanDigit
的声明中为其指定值。
您声明它的方式,RomanDigit
不是 Type
。 RomanDigit Int
是一个 Type
,或者 RomanDigit String
是一个 Type
,或者 RomanDigit (Array Boolean)
是一个 Type
,但 RomanDigit
本身不是 Type
,因为它缺少声明的类型参数 a
。这就是编译器告诉你的。
您需要删除该参数,例如:
data RomanDigit = M | D | C | L | V | I
或在使用RomanDigit
时指定,例如:
newRomanDigit :: Int -> RomanDigit Int
由于参数不存在于任何值中,我怀疑您并不是真的有意将它放在那里。