Function application means a function applied to its arguments: you supply actual input values, and the function works out its result from them.
add(3,4)
Here the function add is applied to the inputs 3 and 4, giving the result 7.
Each time you call a function with values, you are applying it.
Applying single-argument functions
double(5)=10
applies double to the single input 5. The type is double:integer→integer.
The type of a function with two arguments
The function add takes two integers and gives an integer. Its type is
add:integer×integer→integer
where integer×integer is the Cartesian product of the set of integers with itself: the set of all ordered pairs of integers, such as (3,4) (see 4.4.2.2). Using set symbols (4.12.1.1), the same type is written add:Z×Z→Z.
A function really has just one argument
We usually describe add as having two arguments. Strictly, though, its input is a single value: a pair, such as (3,4), taken from the set of all pairs of integers.
add(3,4)=7means: apply add to the single pair (3,4)
So every function takes exactly one argument (which may be a pair or a longer tuple), and gives one result. This viewpoint is useful, and leads on to partial application (4.12.1.4).
More examples of function types
Function
Type
double
integer→integer
add
integer×integer→integer
max of two numbers
real×real→real
volume of a box (length, width, height)
real×real×real→real
repeat a string n times
string×integer→string
Nested application
The result of one application can be used as the argument of another:
double(add(3,4))=double(7)=14
The inner application add(3, 4) is worked out first. Its result, 7, is then the argument of double.
A trace of a larger expression:
double(add(2,double(3)))
double(3)=6
add(2,6)=8
double(8)=16
Worked example
Task: a function volume has type integer×integer×integer→integer and finds l×w×h. Say what volume(2,3,4) means, and evaluate double(volume(1,2,3)).
volume(2,3,4) is the application of volume to the argument(2,3,4), a triple of integers. It gives 2×3×4=24.
double(volume(1,2,3)): first volume(1,2,3)=6, then double(6)=12.
Check yourself
What is meant by function application?
A function applied to its arguments: giving particular inputs to a function to obtain a result, such as add(3, 4).
What is the type of a function multiply that takes two integers and returns an integer?
integer×integer→integer.
What does integer×integer mean?
The Cartesian product of the set of integers with itself: the set of all ordered pairs of integers.
Evaluate double(add(1, 2)) when double doubles and add adds