Juan Figueira
Juan Figueira

Reputation: 161

Couln't match type

I have a problem with this code:

 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

When run, it produces this error:

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

Upvotes: 0

Views: 71

Answers (1)

leftaroundabout
leftaroundabout

Reputation: 120711

The problem is (-list!!a!!2). Yes, this looks like an operator section, analogously to (+list!!a!!2). But, alas, the minus operator is traditionally used also as a lone negative-prefix, and Haskell has put that special case into the language; so (-list!!a!!2) is actually just a negative number and not a subtractor-function. You can use (subtract $ list!!a!!2).

Upvotes: 6

Related Questions