occurences :: (Eq a, Num B)/> => a -> [a] -> b occurences _ [] = error "The list is empty" occurences x xs = sum [1 | y <- xs, x == y]

The above function does work but i was wondering whether you can do the same thing using guards.

Here is my second attempt (not complete, does not work)

occurences :: (Eq a, Num B)/> => a -> [a] -> b occurences _ [] = error "The list is empty" occurences x (y:ys) | x==y = "increment the variable" AND occurences x ys | otherwise occurences x ys

Is it possible to do it using guards? In this case i would have to increment a variable and return it but i do not know whether its possible in Haskell.