What is “point free” style (in Functional Programming)?

前端 未结 5 1145
情深已故
情深已故 2020-11-27 12:33

A phrase that I\'ve noticed recently is the concept of \"point free\" style...

First, there was this question, and also this one.

Then, I discovered here the

5条回答
  •  清歌不尽
    2020-11-27 13:12

    Just look at the Wikipedia article to get your definition:

    Tacit programming (point-free programming) is a programming paradigm in which a function definition does not include information regarding its arguments, using combinators and function composition [...] instead of variables.

    Haskell example:

    Conventional (you specify the arguments explicitly):

    sum (x:xs) = x + (sum xs)
    sum [] = 0
    

    Point-free (sum doesn't have any explicit arguments - it's just a fold with + starting with 0):

     sum = foldr (+) 0
    

    Or even simpler: Instead of g(x) = f(x), you could just write g = f.

    So yes: It's closely related to currying (or operations like function composition).

提交回复
热议问题