I'm trying to use filter (though I can also use map and/or foldr) to find the max element of a list.
I tried filtering out every number less than max but it refuses to accept max as a filter argument.
Here's my code:
max' :: Ord a => [a] -> a
max' xs = filter (< max) xs
Here's the error I get:
* Couldn't match type `a' with `a0 -> a0 -> a0'
`a' is a rigid type variable bound by
the type signature for:
max' :: forall a. Ord a => [a] -> a
at Prog8.hs:50:1-25
Expected type: [a0 -> a0 -> a0]
Actual type: [a]
* In the second argument of `filter', namely `xs'
In the expression: filter (< max) xs
In an equation for max': max' xs = filter (< max) xs
* Relevant bindings include
xs :: [a] (bound at Prog8.hs:51:6)
max' :: [a] -> a (bound at Prog8.hs:51:1)
Is there a way to write max' in a simple filter function (or maybe combine it with map or foldr)?