r/functionalprogramming • u/jacobissimus • Jun 02 '24
Question Are there any technical benefits of point free programming?
I usually think of writing point free functions as a way to keep thinking conceptually about a program as the combination of smaller functions. There are definitely situations where it can make code more readable and times where it makes things more complicated.
Lately I've been wondering though if there's any situation where point free functions would offer any significant technical advantage or disadvantage?
26
Upvotes
12
u/Raziel_LOK Jun 02 '24
Maybe save some allocation and length, but I don't think it is worth. Tbh I just think it looks cool, not very practical and makes readability worse.
3
u/taelor Jun 02 '24
I’ve never heard the term point free functions, can you provide and explanation ?
9
u/metazip Jun 02 '24
Maybe there is something here:
From Function-Level Programming to Pointfree Style, look at advantages...
or here: FP trivia
or here: while-loop in pointfree
8
u/corisco Jun 02 '24
From the point of view of the model, tacit programming is based on combinatory logic, so it has the same benefits as that logic. I don't know if you would consider this an advantage, but because combinatory logic doesn't have free variables, you are able to extend standard first-order logic with it, which isn't true for lambda calculus.
In programming, there are also some benefits to having CL. For example, you don't have to deal with substitutions, which makes the language simpler to implement. In fact, there are some BIOS languages that leverage that fact to their benefit.
But if you have both models available, like one has in Haskell, then there are some problems that are more naturally expressed with tacit programming. Also, GHC can do better optimizations when you don't have any variable binding.
8
u/yawaramin Jun 02 '24
I think it's pointless.
3
u/imihnevich Jun 03 '24
I honestly don't really like haskell style pointfree with it's right-to-left application, but I prefer OCaml style with
x |> f1 |> f2 |> f3I think it's very readable3
u/[deleted] Jun 03 '24 edited Jun 03 '24
Some are listed on https://en.wikipedia.org/wiki/Concatenative_programming_language
This sound good for me.
Also imagine having to use let binding in unix pipeline look terrible
find data | grep workvslet d = find data in grep workd2
u/Massive-Squirrel-255 Jun 06 '24
It avoids errors arising from accidental variable reuse.
Now the similar variable names
prob_foldand prot_foldare both in scope in the area in parentheses. If you don't needprob_fold` for anything after that then this is risky because you have the risk of using it in the wrong place if the two variables are the same type. (Which happens a lot in array programming for example where everything is the same type: an array)Point free style is thus one way of managing scope.
3
u/akshay-nair Jun 02 '24
It can help with the mental overhead while reading code as there are fewer variables to keep in your head. No "real" technical benefits other than that.
Although I think the most important thing is to not force it into a language where the practice is not idiomatic. Writing pointfree haskell/ocaml feels natural whereas forcing pointfree js/ts can feel awkward at times.
-1
u/tbm206 Jun 02 '24
If every program in the world used point free style, a few megabits might be saved and the environment will be slightly happier
-1
u/bravopapa99 Jun 02 '24
Only to impress people.