以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)
怎么了?
以下所有表达式都得到评估而不会发生意外:
(+2) 1 -- 3
(*2) 1 -- 2
((-)2) 1 -- 1
(2-) 1 -- 1
(/2) 1 -- 0.5
(2/) 1 -- 2.0
Run Code Online (Sandbox Code Playgroud)
但不是这个:
(-2) 1 -- the inferred type is ambiguous
Run Code Online (Sandbox Code Playgroud)
GHC抛出一些关于推断类型不明确的错误.为什么?