purescript - 这个纯脚本构造函数有什么问题?
问题描述
尝试为罗马数字创建构造函数:
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
是 a Type
,或者RomanDigit String
是 a Type
,或者也许RomanDigit (Array Boolean)
是 a Type
,但RomanDigit
它本身不是 a Type
,因为它缺少声明的类型参数a
。这就是编译器告诉你的。
您需要删除参数,例如:
data RomanDigit = M | D | C | L | V | I
或者在使用时指定它RomanDigit
,例如:
newRomanDigit :: Int -> RomanDigit Int
由于该参数不存在于任何值中,因此我怀疑您并不是真的打算将它放在那里。
推荐阅读
- c - Makefile 产生错误但构建良好?
- c# - 为什么 TLS 与非安全 http 相关?
- haskell - 代数类型 - Haskell
- javascript - 如何根据 URL 参数显示表格行
- sql-server - 在 Visio 的组织结构图中刷新外部数据(来自 SQL Server)
- javascript - 从嵌套地图对象javascript中删除重复项
- linux - 如何将值从一列复制到另一列?
- node-red - 从 Node-Red 向 IoT Central 发送数据,不需要 dps-keygen
- python - Panda:使用 lambda 函数通过添加两列来创建新列
- javafx - 如何控制克拉在 TableView 列标题中的位置?