14

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).

5

2 Answers 2

14

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:

  • Don't compose with curried composition, it's just too complicated to dissect,e.g.,(sort .) . (++) is best written \xs ys -> sort (xs ++ ys).
  • Do use any combinator from the standard 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.

12

If in doubt, just compose functions with (.). Don't step into flips and swaps and (.) . (.)s

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.