After reading this article I understand that >=> (Kleisli arrow) is just a higher order function to compose functions, that return "monadic values". For example:
val f: A => M[B] = ... val g: B => M[C] = ... val h: A => M[C] = f >=> g // compose f and g with Kleisli arrow
It looks like a simple composition of "simple" functions (i.e. pure functions that return simple values):
val f: A => B = ... val g: B => C = ... val h = f andThen g; // compose f and g
Now I guess this "simple" composition andThen conforms to certain laws
- Identity:
f andThen g == gandg andThen f == gfor identity function:f[A](a:A):A = a - Associativity:
(f1 andThen f2) andThen f3==f1 andThen (f2 andThen f3)
And now my questions:
- Does
>=>conform to those laws, where identity isf(a:A) = M[a].unit(a)? - Can we derive the monadic laws from the those laws ? Are those laws and the monadic laws equivalent ?
What you have here is the immediate consequence of this construction being a category.
unitis called like that: it is the unit under composition of Kleisli arrows.(f <=< g) x = f =<< (g x)(where<=<isandThen, and=<<is probably something likeflip(bind)in Scala). The exact steps of the derivation can be found here.