I'm trying to determine the type of (.) map const
.
The type of (.) map
gives me (a1 -> a2 -> b) -> a1 -> [a2] -> [b]
The type of const
is a -> b -> a
So when I'm trying to do (.) map const
, shouldn't the (a1 -> a2 -> b)
of (.) map
unify with (a -> b -> a)
from const
?
Thus, a1
unifies with a
, a2
unifies with b
, b
unifies with a
.
I'm left with a1 -> [a2] -> b
With the unification it should leave me with a -> [b] -> [a]
However, the correct answer is b -> [a] -> [b]
Can someone explain how and why?
a -> [b] -> [a]
and b -> [a] -> [b]
are the same type (and so is, for example, foo -> [bar] -> [foo]
). The names of type variables carry no meaning, so as long as the same ones are in the same places, the labels they have don't matter.
Answering your comment on @JosephSible's answer, it appears GHCi unification is favoring the type variables from map
. This is mere order of operations and arbitrary:
map' :: (mapA -> mapB) -> [mapA] -> [mapB]
map' = map
dot :: (dotB -> dotC) -> (dotA -> dotB) -> dotA -> dotC
dot = (.)
const' :: constA -> constB -> constA
const' = const
And
*Main> :t dot map' const'
dot map' const' :: mapB -> [mapA] -> [mapB]
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