把否定性作为一种功能

时间:2015-07-26 14:53:08

标签: haskell

我试图弄清楚如何让haskell满意以下等式:

No instance for (Num (Int -> Int))
  arising from a use of syntactic negation
In the second argument of ‘either’, namely ‘(- 1)’
In the expression: either id (- 1)
In an equation for ‘f’: f = either id (- 1)
抱怨道:

f = either id (\x -> x-1)

我是否必须诉诸

$this->assertContains( $randad, $adUnitArr );

或者是否有类型签名可以使其有效?

1 个答案:

答案 0 :(得分:4)

您可以按照建议使用\x -> x - 1,或subtract 1。前缀否定是一种特殊情况:(-1),与(1-)不同,doesn't become a section