Many haskell programmers, including me, like pointless style, especially when writing complicated parsers. They make code more readable and less verbose. But sometimes, it's just the other way round (for instance while abusing the instances of Monad
and friends for (->) a
).
Please give me some basic guideline, when do you think that pointless style is useful and when not. For instance, I always use a lambda if I had to use a partial composition instead (something like flip ((.) . take) . drop
).
Point-free style means programming where you don't have to name arguments or intermediate values. The main reason we do it is to be able to code at the right level of abstraction. You don't want to be thinking about, "How do I name this function?" or "How do I name this argument?" Stuff like that.
Point free style means that the code doesn't explicitly mention it's arguments, even though they exist and are being used. This works in Haskell because of the way functions work.
This is obviously a matter of personal style. I think that pointfree style is a tool for clarifying your ideas, and viewing (->) a
as a Monad
and (->)
as an Arrow
is a good thing if it serves that purpose.
I can think of one do and one don't:
(sort .) . (++)
is best written \xs ys -> sort (xs ++ ys)
.Control.*
modules, e.g., write curry (negate *** (+1))
using (->)
as an Arrow
and ap (zipWith (+)) tail
using (->) [a]
as a Monad
.The reason to involve combinators from common control types isn't just to make your meaning clear but also it reminds you that these exists and are often useful, not only for making pointfree definitions but also for solving problems.
As with all things one should be careful not to over do it. A pointfree definition involving too many combining functions can quickly become complicated.
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