A cup contains 50 spoonfuls of brandy, and another contains 50 spoonfuls of water. A spoonful of brandy is taken from the first cup and mixed into the second cup. Then a spoonful of the mixture is taken from the second cup and mixed into the first. Is there more or less brandy in the second cup than there is water in the first cup?This is a nice example of a problem that's trivial if you know how to look at it and more complex if you approach it in a straightforward, brute force way. One could do the calculation. It's not that difficult. But the easy way to see that the amount of brandy in the water cup is the same as the amount of water in the brandy cup is to realize that both cups end up with the same total amount of liquid—the same amount as they started with, 50 spoonfuls. A certain amount of brandy is in the water cup. The amount of water that was displaced was transferred back to the brandy cup. Therefore, the two amounts are the same.

This is related to what has come to be called point free programming, which is programming by composing functions rather than by describing the effect of functions on their arguments. For example

f(x) = 2*x +3

is the same as

f = (+ 3) . (2 *)

The second defines f as the composition of the two functions that, in order, double the argument and add 3 to the argument.

## No comments:

Post a Comment