不匹配类型

Jua*_*ira 0 haskell

我有这个代码的问题:

 rango2 :: Int -> [Int] -> [[Int]] -> [Int]
 rango2 a b list = if (verif (map(+list!!a!!2)(list!!a)) (map(-list!!a!!2)(list!!a)) (b)) then [1]
              else [0]

 verif :: [Int] -> [Int] -> [Int] -> Bool
 verif a b c = if ((c!!0 < ((a!!0)+1)) && (((c!!0)+1) > b!!0) && (c!!1 < ((a!!1)+1)) && (((c!!1)+1) > b!!1)) then True
          else False
Run Code Online (Sandbox Code Playgroud)

运行时,会产生以下错误:

Couldn't match type `Int' with `Int -> Int'
Expected type: [[Int -> Int]]
  Actual type: [[Int]]
In the first argument of `(!!)', namely `list'
In the first argument of `(!!)', namely `list !! a'
In the expression: list !! a !! 2
Run Code Online (Sandbox Code Playgroud)

lef*_*out 6

问题是(-list!!a!!2).是的,这看起来像一个操作员部分,类似于(+list!!a!!2).但是,唉,减号运算符传统上也被用作一个单独的负前缀,而Haskell将这种特殊情况放入语言中; 所以(-list!!a!!2)实际上只是一个负数而不是减法函数.你可以用(subtract $ list!!a!!2).