My signature seems to be disabled. Since then I found out why. Now I'm interested in learning more about the alleged GHCI signature on my typo. I tried to get this code to work:
elemNum :: (Eq a, Num b) => a -> [a] -> b
elemNum e l = f e l
where f _ [] = [] -- this was my typo, supposed to read 0
f e (x:xs)
| x == e = 1 + f e xs
| otherwise = f e xs
Obviously, this does not work for the reason indicated above; but if I delete my signature, it compiles (I don’t know why, please explain), and I get this signature:
elemNum :: (Num [a], Eq t) => t -> [t] -> [a]
I have never seen a typeclass Num [a]before. What does it mean and how does it compare with (Num a) => [a].
source
share