遵循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怎么了?
发布于 2011-06-03 15:28:59
哈斯克尔认为你试图从abs中减去3,并抱怨abs不是一个数字。在使用一元求反运算符时,需要添加括号:
abs (-3)发布于 2011-06-03 15:30:53
解释器认为你指的是abs - 3而不是abs (-3)。您需要使用方括号来消除代码的歧义,并确保您打算使用一元"-“函数,而不是减法运算符。
https://stackoverflow.com/questions/6224212
复制相似问题