Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.45 KB

File metadata and controls

51 lines (40 loc) · 1.45 KB

Partial Application

Know what is meant by partial function application for one, two and three argument functions and be able to use the notations

What is partial application?

Partial application is the process of fixing a number of arguments to a function and then producing another function which only takes the remaining arguments.

Why is partial application used?

Partial application is used to make a general function more specific allowing it to be used with greater ease in the program.

Example

add x y = 
	x + y

In the example below, the add function takes two arguments and returns their sum. Say you wanted to add 2 to a number a user gives you? You don't want to have to pass the argument 2 into the add function again and again. Instead you could partially apply the add function to the value 2.

addTwo = add 2

Now the addTwo function takes one argument and add's 2 to it.

Additional Information

The function add takes two integers as arguments and gives an integer as a result. Viewed as follows in the partial function application scheme:

add: integer → (integer → integer)

add 4 returns a function which when applied to another integer adds 4 to that integer.

The brackets may be dropped so function add becomes add:

integer → integer → integer

The function add is now viewed as taking one argument after another and returning a result of data type integer.