我是Haskell的新手,遇到類型系統問題。我有以下功能: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
哈斯克爾與迴應:
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
我認爲這個問題是我需要以某種方式告訴哈斯克爾總的類型,也許這與類型類展會關聯,但我不知道該如何實現。謝謝你的幫助。