Higher-order functions

From Fōrmulæ wiki
Jump to: navigation, search

This page is the answer to the task Higher-order functions in the Rosetta Code.

Description (from Rosetta Code)

Task

Pass a function as an argument to another function.

Program

The following defines a function that takes a function as the first argument and two more arguments. It makes a function application with the argument function and the two arguments:

HighOrderFunctionsProgram.png

Case 1

We define a function that do an addition of two numbers

HighOrderFunctionsOutput1.png

Then we pass it to the first function.

HighOrderFunctionsOutput2.png

Case 2

We define a function that, given two numbers, retrieves a list with an addition, a subtraction, a multiplication, a division and a exponentiation of the numbers.

HighOrderFunctionsOutput3.png

Then we pass it to the first function.

HighOrderFunctionsOutput4.png