-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: Towards pure FP using IO Monads and Kleisli composition #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
// val ac = ab `;` bc | ||
implicit final class InfixNotationForPointFree[A, B](private val ab: A => B) extends AnyVal { | ||
// Alias: In Haskell compose is a simple dot | ||
@inline def `.`[C](bc: B => C): A => C = PointFree.compose(ab, bc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be simply
@inline def `.`[C](bc: B => C): A => C = bc.compose(ab)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also be very careful with this choice, since the .
is already integral part of the language syntax, the risk of creating confusion seems to me too high for the benefit gained.
Also considering that compose
and andThen
are already in the stdlib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that it would be a better choice to use andThen
and avoid the aliasing for dot. Again, this was just left behind as a trace of what I was trying to do.
If I may say, I'm generally unconvinced about the gained benefits of defining custom versions of the popular combinators/datatypes. I'm not trying to criticise just for the sake of it. I'm reasoning that the usefulness of having a library that provides such functional affordances is in the breadth of such apis. Using an fp lib like "cats/scalaz" provides a very broad spectrum of previously unavailable functionalities, that concurs to enable a consistent and terse syntax to powerfully combine operations. I think that those are necessary to express a side-effecting program in such a way that it's worth paying the price of the added abstraction. Just adding food for thought, please consider how the proposal might actually make it less clear what is the real benefit of going to such length, only to express something that seemed so simple before. The risk is that people trying to approach fp, could be actually unconvinced by all the added ceremony with no blatantly clear benefits. |
First things first let me thank you for the time you have spent going through this PR. As you can see in the title of the PR this is a Work In Progress, and its purpose is just educational for now. My idea was to introduce a clear distinction between the description of the program and its execution.
I know that this is not really useful in a production environment and I wouldn't use this approach in a real project, but quite the opposite.
Keep in mind that a development rule of this project is that
I like the approach expressed in Cats more than anything else, and my idea was actually to introduce some of the fundamental concepts of that library through a direct link from the simpler code that you can find in here. I think that introducing the Category Theory using simple examples helps a lot in the process of switching from the imperative to the functional paradigm. The real aim of this little project is to bring more people to Scala and FP. That's its sole purpose, so there's no chance to use it apart from in a well confined space made for learning some principle which can be then extended.
That's a very good point indeed. I don't really want to scare people, and I can leave this piece of code out of scope. I also think that these subjects are hard to grasp for a newcomer at first, and that it takes time and effort to understand why we should embrace the functional paradigm and its ceremonies. |
Thanks for the answer I'm conscious of the problem with FP in Scala that justifying the effort undertaken on a very basic use cases becomes hard, yet using the full power of all combinators and type classes becomes overwhelming for those unfamiliar, thus keeping people at a distance in both cases. |
I totally agree on that. |
The objective is to refactor the current program in order to be executed only at the end of the world and to enclose the IO side effects into an IO Monad, while composing functions using Kleisli Composition.
Changes proposed in this Pull Request:
Monad
andKleisliComposition
Notes
Considerations/Implementation Details (optional)
Test Instructions
QA
Screenshots/Screencasts (optional, but should be included when relevant)