[Solved] Higher order function parameter [closed]


Your call to and_ does not see director and "Brad Bird" directly; it gets the function that results from applying director to "Brad Bird" (and similarly for the second argument.

and_ :: (Movie -> Bool) -> (Movie -> Bool) -> Movie -> Bool
and_ f1 f2 (_, rank, dir) | ...

The bigger problem is that you can’t compare functions for equality. Even assuming director itself was passed as a distinct argument, you can’t check if it’s the same function referred to by director.

What you want is to simply apply each of the first two functions to the third function and use && on the results:

and_ :: (Movie -> Bool) -> (Movie -> Bool) -> Movie -> Bool
and_ f1 f2 m = f1 m && f2 m

f1 and f2 already “know” which part of the Movie argument they are checking against.

2

solved Higher order function parameter [closed]