相关疑难解决方法(0)

"没有实例"错误

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)

怎么了?

haskell ghci

6
推荐指数
2
解决办法
1502
查看次数

为什么一元减运算符在这个表达式中有问题:( - 2)1?

以下所有表达式都得到评估而不会发生意外:

(+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抛出一些关于推断类型不明确的错误.为什么?

haskell infix-operator

5
推荐指数
1
解决办法
478
查看次数

标签 统计

haskell ×2

ghci ×1

infix-operator ×1