以下是一个例子http://en.wikibooks.org/wiki/Haskell/Beginning 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
怎么了?
Haskell 认为你正在尝试减法3
from abs
,并且抱怨说abs
不是一个数字。使用一元否定运算符时需要添加括号:
abs (-3)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)