以http://en.wikibooks.org/wiki/Haskell/Beginning为例
Prelude> let abs x = if x < 0 then -x else x
Prelude> abs 5
5
Prelude> abs -3
<interactive>:1:6:
No instance for (Num (a0 -> a0))
arising from the literal `3'
Possible fix: add an instance declaration for (Num (a0 -> a0))
In the second argument of `(-)', namely `3'
In the expression: abs - 3
In an equation for `it': it = abs - 3
Run Code Online (Sandbox Code Playgroud)
怎么了?
ham*_*mar 14
哈斯克尔认为你想减3从abs,并抱怨abs是不是一个数字.使用一元否定运算符时需要添加括号:
abs (-3)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1502 次 |
| 最近记录: |