# What are the applications of using functions whose heads are also functions?

I noticed that it is possible to construct something like f[x][y]. Displaying this in TreeForm indicates that this expression has head f[x]; and it seems to imply that this is really a function of y, and the name of this function is another function f[x]!

So what are the uses of such constructs? Could x for example be like an index that labels a family functions?

• wikipedia>> Currying
– kglr
Commented Nov 5, 2014 at 19:32
• E.g. SortBy[Last], indexed variables x[1][t], x[2][t] in a DE system,....I just used Through[OptionValue["EventFunctions"][ics]] in this answer. Commented Nov 5, 2014 at 19:48
• In V10 new operator forms have been introduced. One can use SubValues to get similar functionality. It can be quite useful. Commented Nov 5, 2014 at 20:17
• I often use it when I want to reuse expensive results. For example, in this case of function memoization, or when I want to fix some of a function's parameters and Map over another set. Commented Nov 6, 2014 at 0:26

One way to think about this syntax is in terms of "functions with parameters that accept inputs". The normal way this is written is

function[inputs..., parameters...]


this structure leads to a somewhat awkward syntax when mapping over a list of inputs:

list = {1.234, 5.678};
(Round[#1, 0.1] & ) /@ list

(* {1.2, 5.7} *)


The two-argument-list syntax allows you to construct a parameterized operator that acts upon inputs:

round[a_][x_] := Round[x, a];
round[0.1] /@ list

(* {1.2, 5.7} *)


which is a little tidier. I believe the explosion of built-in functions which permit this syntax is due to the new Query function in version 10:

Query[round[0.1]][list]

(* {1.2, 5.7} *)


In general, there is a lot more support for more formal functional programming style in version 10.