I'm trying to define a function that given an element and a list to count the number of times that element appears on that list, then I have:
cuantasVecesAparece :: Eq a => a -> [a] -> Int
cuantasVecesAparece p [] = 0
cuantasVecesAparece p [x:xs] = if p == x
then 1 + cuantasVecesAparece xs
else cuantasVecesAparece xs
But I get the following error:
ERROR file:.\ff1.hs:272 - Type error in application *** Expression : p == x *** Term : p *** Type : [a] *** Does not match : a *** Because : unification would give infinite type
I do not understand why I'm taking p
as a list.