相关疑难解决方法(0)

Haskell中一元运算符的前缀形式

在GHCi中:

  1. 序曲>(+3)2
    5
  2. 序曲>(*3)2
    6
  3. 前奏>(/ 3)2
    0.6666666666666666
  4. 前奏>( - 3)2
    没有实例(Num(t - > t1))
    来自文字':it =( - 3)23' 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

如何更正最后一个使其返回-1?

haskell unary-operator ghci prefix-operator

3
推荐指数
2
解决办法
2039
查看次数

为什么(-2)与Haskell中的(\ x - > x - 2)不同?

我正在学习使用CIS194(spring13)的Haskell.今天当我试图处理作业4练习1时,我收到了错误

fun1' :: [Integer] -> Integer
fun1' = foldl' (*) 1 . map (-2) . filter even
Run Code Online (Sandbox Code Playgroud)

据说:

error:
    ? No instance for (Num (Integer -> Integer))
        arising from a use of syntactic negation
        (maybe you haven't applied a function to enough arguments?)
    ? In the first argument of map, namely (- 2)
      In the first argument of (.), namely map (- 2)
      In the second argument of (.), namely map (- 2) . filter even
   |
12 | fun1' …
Run Code Online (Sandbox Code Playgroud)

haskell

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

标签 统计

haskell ×2

ghci ×1

prefix-operator ×1

unary-operator ×1