Im trying to infer the type of:
((.) foldr) The type i manually infer differs from the one ghci infer. Here's what i do:
(.) :: ( b -> c) -> (a->b)->a->c foldr:: (a'->b'->b')->b'->[a']->b' Now my first doubt. Foldr has to unify with b->c foldr has to unify with (b->c) but there are more than one way to make it happen; like
b ~ (a'->b'->b') c ~ b'->[a']->b' or..
b ~ (a'->b'->b')b'->[a'] c ~ b' How do i know which to take?
Doing different examples in ghci i arrived to the conclusion that haskell tries to unify types in a non greedy fashion for the first argument (This conclusion is totally experimental and can be totally wrong, maybe its the reason i arrive to a wrong type for the function, but is what i thought of the type inferences ive tried on haskell). So, assuming this is true the configuration haskell tries to unify first is:
b ~ (a'->b'->b') c ~ b'->[a']->b' So now..
(.)foldr :: (a->b)->a->c Substituting b and c:
(.)foldr :: (a-> (a'->b'->b') )->a->b'->[a']->b' Which is close enough the only problem i have are the parentheses in the expression (a'->b'->b') Why can i remove them when you cannot remove those in the original foldr, and the function is gonna be an input for foldr. Why after applying the composition functor you can use partial application? Is there a rule for that? Also i would like if someone coudl confirm or deny the "non greedy" type matching..