Clarifying some functional Programming jargon in scala

81 Views Asked by At

Although at this point i am quite ok with function1 Monad and its transformer version i.e. Kleisli composition, going back into a book I originally started with, i still can't really understand the jargon that what used, somewhat to stress the difference between a typical Monadic behavior and kleisli composition. I find that distinction non-intuitive and misleading.

I suspect the author wanted to stress the notion of deferred evaluation that comes Function1 Monad, compared to other monad, but that's just working with the effect of function.

Anyway, I wonder if someone can clarify some the author statement:

Power of function application over the additional structure that we call effects— You’ve seen how ordinary functions compose and how they can be applied over an argument. But that may not be enough for domain models, where you need to apply a function with custom behavior at the point of application. Look at the function application that flatMap offers: def flatMap[A, B](ma: F[A])(f: A => F[B]): F[B]. It applies A => F[B] to F[A] and then flattens F[F[B]] to F[B]. Here you flatten at the point of application so that you get back the structure you supplied to flatMap. This enables you to sequence the function application over the effectful structure of F[_].

.......

Power of function composition over the additional structure that we call effects— If you have a function f: A => F[B] and another function g: B => F[C], where F is a monad, then you can compose them to get A => F[C]. This isn’t ordinary function composition; it’s composition of monadic functions. It’s also called Kleisli composition;

.......

The Jargon i don't get is "Power of function application" vs "Power of function composition" Especially when the author try to make the point with the following:

It applies A => F[B] to F[A] and then flattens F[F[B]] to F[B]. Here you flatten at the point of application so that you get back the structure you supplied to flatMap.

The same thing happen wether you start with a monadic function or just an effect. To me an effect can even be seen as the function Unit => F[A].

So i am not crystal clear if i am not understanding what the author is trying to stress, or is it that it is the author that is not making its point properly and i already got the all point.

What's the point of application anyway ? how is it not in function1 ?

0

There are 0 best solutions below