Haskell中一元运算符的前缀形式 [英] Prefix form of unary operator in Haskell

查看:139
本文介绍了Haskell中一元运算符的前缀形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GHCi中:

In GHCi:



  1. 前奏>(+3)2

    5

  2. 前奏>(* 3)2

    6

  3. 前奏>(/ 3)2

    0.6666666666666666

  4. Prelude>(-3)2

    没有实例用于(Num(t - > t1))

    3'在< interactive>:1:2

    可能的修正:为(Num(t - > t1))添加实例声明

    In表达式:3

    在表达式中:( - 3)2

    的定义中它:'it =( - 3)2

  1. Prelude> (+3) 2
    5
  2. Prelude> (*3) 2
    6
  3. Prelude> (/3) 2
    0.6666666666666666
  4. Prelude> (-3) 2
    No instance for (Num (t -> t1))
    arising from the literal 3' at <interactive>:1:2
    Possible fix: add an instance declaration for (Num (t -> t1))
    In the expression: 3
    In the expression: (- 3) 2
    In the definition of
    it': it = (- 3) 2


如何修正最后一个让它返回-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆