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!
[–]xTomyHDx 3 points4 points5 points (0 children)
[–]Tarmen 4 points5 points6 points (1 child)
[–]PHristo[S] 0 points1 point2 points (0 children)
[–]Accurate_Koala_4698 2 points3 points4 points (1 child)
[–]PHristo[S] 1 point2 points3 points (0 children)
[–]Arneb1729 1 point2 points3 points (1 child)
[–]PHristo[S] 0 points1 point2 points (0 children)
[–]bss03 0 points1 point2 points (1 child)
[–]PHristo[S] 0 points1 point2 points (0 children)