On Sat, Jul 31, 2010 at 20:07, Bruno Medeiros
<brunodomedeiros+spam@com.gmail> wrote:
Consider the familiar functional idiom "map" (http://en.wikipedia.org/wiki/Map_%28higher-order_function%29)
What would you call such a function parameter (either for map or just generally).
What parameter?
That is, what would you call a function that takes one parameter of some type, and produces another object/data from that input?
Do you mean the partial application of map, is in D with map!"a*a" ? (without any argument).
Is there any usual name/term for this, I wonder, or not really?
Not sure if I'm saying something obvious to you, but map is a higher-order function: a function that acts on functions, either taking them as parameter(s) or as results. So are filter, fold/reduce, unfold, scan, compose, power (of a function: power(f, n) = f(f(f(... n times)))
For map, filter or reduce, the function is just a parameter among two. Most of the time, what they create is not a function.
In curried language like Haskell, you can easily create the partial application of a function: n-args functions are in fact n 1-arg functions each delivering the next step (a function).
So map x*x [0,1,2,3,4] is [0,1,4,9,16], but map x*x is a function, waiting for an iterable and returning its transformation through x*x. In not-curried language, map x*x is considered a partial application of map.
Note in D the asymmetry between the function which is a compile-time argument and the range, a runtime argument. A recent change in Phobos (for the next release) by Andrei will allow us to do:
alias map!"a*a" squarer; // squarer is a _generic_ function taking any range, as long as the operation a*a makes sense for the range elements.
Before, we could do this with reduce, but not map and filter. That was originally to avoid a bug in the compiler :-) but it's easy to code and very useful.
We could have a map(fun, range) in D, I guess. Gone the currying, but welcome runtime functions.
Philippe