I found out recently that the pointfree for \x -> f x x
is join f
, and wanted to understand why. I started here:
join :: Monad m => m (m a) -> m a
then got stumped because I'm not familiar with the "function monad". Could someone help me with the type derivation that explains the equality?
This is a pretty simple algebraic transformation of the Monad ((->) r)
on the type level. Watch as we specialize and simplify the type of join
.
join :: Monad m => m (m a) -> m a
join :: ((->) r) (((->) r) a) -> ((->) r) a -- Specializing
join :: (r -> (r -> a)) -> (r -> a) -- Infix
join :: (r -> r -> a) -> r -> a -- Simplifying
If we substitute x ->
for m
in the type of join
, we get (x -> x -> a) -> x -> a
. If we apply f
to that (which I assume has the type x -> x -> a
for some x
and a
), we get x -> a
, which is also the type of \x -> f x x
.
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