Haskell: type inference and function composition

Posted by Pillsy on Stack Overflow See other posts from Stack Overflow or by Pillsy
Published on 2009-08-28T00:18:57Z Indexed on 2010/03/23 7:53 UTC
Read the original article Hit count: 375

Filed under:
|
|

This question was inspired by this answer to another question, indicating that you can remove every occurrence of an element from a list using a function defined as:

removeall = filter . (/=)

Working it out with pencil and paper from the types of filter, (/=) and (.), the function has a type of

removeall :: (Eq a) => a -> [a] -> [a]

which is exactly what you'd expect based on its contract. However, with GHCi 6.6, I get

gchi> :t removeall
removeall :: Integer -> [Integer] -> [Integer]

unless I specify the type explicitly (in which case it works fine). Why is Haskell inferring such a specific type for the function?

© Stack Overflow or respective owner

Related posts about haskell

Related posts about beginner