I am trying to write a One line function where you enter a number and a List, and it returns the highest value.
For example:
Input: getMax 5 [1,4,7]
Output: 7
Here is my current code:
getMax :: (Ord a) => a -> [a] -> a
getMax f xs = foldr max f xs
Now I want to extend my function so that instead of a number I can enter a Lamda function to be compared.
For example:
Input: getMax (\x -> mod x 5) [1,4,7]
Output: 4
But I cannot get it to work.
I get an error message:
No instance for (Show (Integer -> Integer))
which I don't really understand.
I tried to change the type signature, but that did not help.
thanks in advance!
getMax 5 (map (\x -> mod x 5) [1,4,7]), perhaps?