Cosmic Badal
Cosmic Badal

Reputation: 13

Construct a list of all the integers in a list l which are greater than a given value v in Haskell

I would expect

input : maxNumbers 5 [1,4,5,6,8,4,5,8]

output : [6,8,8]

My Approach:

maxNumbers ::a =>[a] -> [a]
maxNumbers n (x:xs) = enumFrom(n < x) + maxNumbers n xs

Upvotes: 0

Views: 164

Answers (1)

peri4n
peri4n

Reputation: 1421

What is lacking in your signature is a way to tell haskell that the elements in your list can be ordered (the Ord typeclass). This is not true for every type so you have to take that into account.

maxNumbers :: Ord a => a -> [a] -> [a]
maxNumbers x = filter (>x)

Is an implementation that should work.

Upvotes: 5

Related Questions