views:

953

answers:

3

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 they mention "Another topic that may be worth discussing is the authors' dislike of point free style."

What is "point free" style? Can someone give a concise explanation? Does it have something to do with "automatic" currying?

To get an idea of my level - I've been teaching myself Scheme, and have written a simple Scheme interpreter... I understand what "implicit" currying is, but I don't know any Haskell or ML.

+18  A: 

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

Dario
Ahh I see! So you build up new functions always just by combining other functions rather than declaring arguments... Very elegant!
Paul Hollingsworth
I really dislike having to come up with new names for variables/arguments when I'm programming. That's one big reason I love point-free style!
Martijn
In what way is it related to Currying?
kaleidic
@kaleidic: Because without having variable names, you need to compose partially applied functions. That's what we call currying (or, more precisely, what is made possible through currying)
Dario
+7  A: 

Point-free style means that the arguments of the function being defined are not explicitly mentioned, that the function is defined through function composition.

If you have two functions, like

square :: a -> a
square x = x*x

inc :: a -> a
inc x = x+1

and if you want to combine these two functions to one that calculates x*x+1, you can define it "point-full" like this:

f :: a -> a
f x = inc (square x)

The point-free alternative would be not to talk about the argument x:

f :: a -> a
f = inc . square
sth
Stupidly, in Haskell, the 'point-free' way is usually the one that looks pointier (more periods). This annoyance makes an excellent mnemonic. (The book Real World Haskell comments on this.)
Dan
+1  A: 

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.

For instance:

myTake = take

returns a function that takes one argument, therefore there is no reason to explicit type the argument unless you just want too.

Rayne