Haskell higher order function problem
-
25-10-2019 - |
Question
Current Code
I have two functions as
f1::Int->Int->Int
f1 a b | a==1 && b==1 = 1
| otherwise = 0
applying this function to a [Int]
by a another function
f2::[Int]->[Int]->[Int]
f2 a b = map f1 a b
Error
Type error in application
*** Expression : map f1 c d
*** Term : map
*** Type : (e -> f) -> [e] -> [f]
*** Does not match : a -> b -> c -> d
Conclution
actually what i requied is to apply the f1
which perform to a Int
to a [Int]
using f2
is this problem can solved in higher order functions ? or any other method ? ... or how can i transform f2
to be a higher order function to take f1
?
Thanks!
Solution
If you want to apply the function to two list you need a different function, namely zipWith.
f2 a b = zipWith f1 a b
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow