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
1
  • 2
    No need to apologise in your question - there's nothing wrong in asking for help. Commented Apr 6, 2018 at 22:45

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.