I have been learning just how powerful the <$> and <*> operators are in Haskell, and how it is possible to define some functions without parameters where they would normally be needed. I followed these steps to change my doThing function and gradually remove its three parameters:
1) doThing x y z = (x + y) * z
2) doThing x y = ((x + y) *)
3) doThing x = (*) <$> (x +)
4) doThing = ((*) <$>) <$> (+)
All of these functions take three numbers x, y, and z, and compute (x + y) * z. I know it's not pretty nor a good programming practice in a practical sense, but I still wonder whether it's possible that any mathematical expression with N variables can be described as a function without explicitly naming those N variables. I have tried more complicated expressions without much success; even the 4th step above is hard for me to wrap my head around.
Yes, it is always possible. Here's one particularly simple algorithm:
For example, here's how that might look for eliminating
zfrom your expression.We can then go again, this time eliminating
y.We could go again, to eliminate
x, but this is already messy enough. The point is that this can all be done purely mechanically, without requiring insight from the person (or machine) doing the point free translation.For fun, here's the final form if you follow this algorithm:
It's obvious that this algorithm is geared towards simplicity over readability of the result!
Full listing for the code to generate that answer: