I made this function:
compose [] = id
compose (x:xs) = x . (compose xs)
And when I asked for the type:
:t compose
compose :: [b -> b] -> b -> b
Why does it give compose :: [b -> b] -> b -> b and not compose :: [a -> a] -> a -> a if a comes first in alphabetic order?
Saying that, I will add this other example:
badImplementationOfCompose [] = id
badImplementationOfCompose (x:xs) = (badImplementationOfCompose xs)
:t badImplementationOfCompose
badImplementationOfCompose :: [a1] -> a2 -> a2
It might give some hints...
I would guess it has to do with the type of . which is
(.) :: (b -> c) -> (a -> b) -> a -> c
and it just starts replacing from there when inferring the type.
a has to be equal to b and b has to be equal to c. So in short my guess is that it tries to keep type variable naming in line with the type variable names in used sub-functions if possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With