Haskell中一元运算符的前缀形式 [英] Prefix form of unary operator in Haskell
本文介绍了Haskell中一元运算符的前缀形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在GHCi中:
In GHCi:
- 前奏>(+3)2
5 - 前奏>(* 3)2
6 - 前奏>(/ 3)2
0.6666666666666666 - Prelude>(-3)2
没有实例用于(Num(t - > t1))
3'在< interactive>:1:2
的定义中它:'it =( - 3)2
可能的修正:为(Num(t - > t1))添加实例声明
In表达式:3
在表达式中:( - 3)2
在 -
- Prelude> (+3) 2
5 - Prelude> (*3) 2
6 - Prelude> (/3) 2
0.6666666666666666 - Prelude> (-3) 2
No instance for (Num (t -> t1))
arising from the literal3' at <interactive>:1:2
it': it = (- 3) 2
Possible fix: add an instance declaration for (Num (t -> t1))
In the expression: 3
In the expression: (- 3) 2
In the definition of
如何修正最后一个让它返回-1?
How can I correct the last one to make it return -1?
推荐答案
Haskell的语法不允许你像这样使用 -
。使用减去
函数:
Haskell's grammar doesn't allow you to use -
like that. Use the subtract
function instead:
(subtract 3) 2
这篇关于Haskell中一元运算符的前缀形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文