we’ve been ask to write a function to see if the result of an applied filter function is an empty list. I tried following approach but it gives me mentioned error.
isListEmpty ::((a -> Bool) -> [a] -> [a]) -> Bool
isListEmpty f | length f == 0 = True
| otherwise = False
Error:
...- Type error in application
*** Expression : length f
*** Term : f
*** Type : (b -> Bool) -> [b] -> [b]
*** Does not match : [a]
the idea is practicing higher order functions.
any idea how can I solve this?
Seems like you have wrong type annotations. Consider the following solution:
Some examples:
Using
lengthis not the best idea, since you have to loop through the entire list to do the check, and the list can even be infinite.nullcan handle this sutiation:Edit 1:
Don’t quite understand what it means, but you may want to do this:
Example usage:
Please provide me with the example of intended function call, if I am wrong.