1

I've been struggling for like an hour to understand some things in higher order functions and now I am at the point that I cannot move any further because of this error:

    hof :: [Integer] -> (Integer -> Integer)
    isIn :: [Integer] -> Integer -> Integer
    isIn [] s = 0
    isIn [] _ = 0
    isIn (h:t) s
        | h == s = 0 {-<-------- error points here here-}
        | otherwise = isIn(t) + 1
    hof s = \n -> isIn s n

      ERROR file:.\Lab2.hs:111 - Type error in explicitly typed binding
      *** Term           : isIn
      *** Type           : [Integer] -> Integer -> Integer -> Integer
      *** Does not match : [Integer] -> Integer -> Integer
amalloy
  • 75,856
  • 7
  • 133
  • 187
  • 2
    No need to apologise in your question - there's nothing wrong in asking for help. – AJF Apr 06 '18 at 22:45

1 Answers1

6

You are missing the second argument in the recursive call to isIn; it should be

 | otherwise = isIn t s + 1
 --                   ^

While not an error, you also have a redundant base case; s and _ are both irrefutable patterns, so just isIn [] _ = 0 is sufficient.

Also not an error, but there is no difference between hof and isIn, as you can eta-reduce the definition to

hof s = isIn s

and again to

hof = isIn
chepner
  • 389,128
  • 51
  • 403
  • 529
  • 1
    Thanks buddy, you helped me the most today, you actually had the tolerance to answer to all my noob questions. If i had more rep i would +1 you but now i am so low i can't :P. – White_Sirilo Apr 06 '18 at 22:54