Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `\x -> f x x` = `join f`?

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?

like image 517
rityzmon Avatar asked Dec 14 '22 05:12

rityzmon


2 Answers

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
like image 196
R B Avatar answered Dec 20 '22 15:12

R B


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.

like image 23
sepp2k Avatar answered Dec 20 '22 17:12

sepp2k