我是 Haskell 的新手,在类型系统方面遇到了麻烦。我有以下功能:
threshold price qty categorySize
| total < categorySize = "Total: " ++ total ++ " is low"
| total < categorySize*2 = "Total: " ++ total ++ " is medium"
| otherwise = "Total: " ++ total ++ " is high"
where total = price * qty
Haskell 回应:
No instance for (Num [Char])
arising from a use of `*'
Possible fix: add an instance declaration for (Num [Char])
In the expression: price * qty
In an equation for `total': total = price * qty
In an equation for `threshold':
... repeats function definition
我认为问题在于我需要以某种方式告诉 Haskell 总计的类型,并可能将其与类型类 Show 相关联,但我不知道如何实现。谢谢你的帮助。