尝试为罗马数字创建构造函数:
data RomanDigit a = M | D | C | L | V | I
newRomanDigit :: Int -> RomanDigit
newRomanDigit 1000 = M
newRomanDigit 500 = D
Run Code Online (Sandbox Code Playgroud)
获取错误消息:
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
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
你给了RomanDigit一个类型参数a,但没有在声明中为它指定一个值newRomanDigit.
你宣称它的方式RomanDigit不是Type.RomanDigit Int是a Type,或者RomanDigit String是a Type,或者可能RomanDigit (Array Boolean)是a Type,但是RomanDigit它本身不是a Type,因为它缺少声明的类型参数a.这就是编译器告诉你的.
您需要删除参数,例如:
data RomanDigit = M | D | C | L | V | I
Run Code Online (Sandbox Code Playgroud)
或者在使用时指定它RomanDigit,例如:
newRomanDigit :: Int -> RomanDigit Int
Run Code Online (Sandbox Code Playgroud)
由于参数不存在于任何值中,我怀疑你并不是真的想要它在那里.
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |