I'm new to Haskell and I have no idea what I'm doing wrong here. The following code generates an error.
numOfPos :: Num a => [a] -> Int
numOfPos xs = length [x | x <- xs, x > 0]
The code just returns the number of positive elements in the list. The list can contain any type of number.
The error says "Could not deduce (Ord a) arising from a use of '<' from the context (Num a)..."
What is the type declaration supposed to be to allow for this function?
(Num a, Ord a) => [a] -> Int
- Louis Wasserman