5

I was looking at GHC.Unicode library source and realized that almost all the Haskell internal libraries avoid tacit programming (aka point-free style) most of the time. Simple functions can be easily converted, such as:

isLatin1 :: Char -> Bool
isLatin1 c = c <= '\xff'

Resulting in:

isLatin1 :: Char -> Bool
isLatin1 = (<= '\xff')

But there are cases where I can't apply it, such as when I have more complex functions, like:

isOctDigit c =  c >= '0' && c <= '7'

Is hard to deduct a way to compose the operations. I don't mean to get in the range, I mean to do multiple operations just by composing functions. The following:

isOctDigit = (>= '0') && (<= '7')

Is not valid, and also (>= '0') . (<= '7') clearly cannot happen because of the different return types.

Taking account these observations, I have the following questions:

  • When should I use point-free programming instead of explicit it all?
  • Why GHC prefer to explicit instead of use partial functions?
  • How can I compose two functions of different types without being explicit, such as in the example?
mipadi
  • 398,885
  • 90
  • 523
  • 479
Marcelo Camargo
  • 2,240
  • 2
  • 22
  • 51
  • 11
    FYI `liftA2 (&&) (>= '0') (<= '7')` is one way to do your example. – luqui Aug 11 '15 at 17:10
  • 8
    That’s quite a few question to be put in, well, one question. – Joachim Breitner Aug 11 '15 at 17:14
  • 5
    This is not really a complete answer, but... I have worked on a few codebases that were meticulous about using the simplest, most obvious looking code everywhere. I found myself pleasantly nimble in modifying them. – Daniel Wagner Aug 11 '15 at 17:21
  • 1
    The first two questions are more on-topic on [Programmers Stack Exchange](https://programmers.stackexchange.com). It's largely a stylistic issue: just pick whatever expresses your particular problem the clearest. – Rufflewind Aug 11 '15 at 23:45
  • 2
    Tacit programming is not a goal per se; it's only a useful tool... when it's useful — there are some cases in which a tacit (point-free) definition is significantly more human readable; there are, however, cases where it's immensely less readable than non-tacit. – Erik Kaplun Aug 12 '15 at 00:08
  • 1
    @Rufflewind - The first question posed is off-topic at Programmers. Ultimately, it boils down to a poll-by-example which is a poor fit for the StackExchange Q&A format. The second question is marginally on-topic but would certainly need some backing research to make it a more interesting and constructive question. And to round out the trifecta, the third question is obviously off-topic for Programmers as it's focused upon implementation only. –  Aug 12 '15 at 02:01

0 Answers0