I am having some troubles with function composition and types.
I would like to compose filter
(which returns a list) with len
, which takes a list as an argument (technically a Foldable
but I am simplifying here).
Looking at the types everything is as expected:
> :t length
length :: Foldable t => t a -> Int
> :t filter
filter :: (a -> Bool) -> [a] -> [a]
So now I would expect the type of (len . filter)
to be
(length . filter) :: (a -> Bool) -> [a] -> Int
while in reality is
> :t (length . filter)
(length . filter) :: Foldable ((->) [a]) => (a -> Bool) -> Int
So it seems I lost some arguments. Is it included in the the Foldable
requirements in some way I am not understanding?
Note that everything works as expected if I do partial application:
> let myFilter = filter odd
> :t myFilter
myFilter :: Integral a => [a] -> [a]
> :t (length . myFilter)
(length . myFilter) :: Integral a => [a] -> Int
> (length . myFilter) [1,2,3]
2