A function is called a higher-order function if its arguments and values are allowed to be functions.
This is an important property that most good programming languages possess.
The composition and tupling operations are examples of functions that take other functions as arguments and return functions as results.
For example, suppose we have two functions f: A → B
and g: B → C
.
Then we can write g • f
in prefix form • (f, g)
.
Viewed in this way, composition is a higher-order function with the following type expression:
(A → B) × (B → C) → (A → C)
.
The map function takes one argument, a function f: A → B
, and returns as a result the function map(f): Lists[A] → Lists[B]
, where map(f)
applies f
to each element in its argument list.
For example, let f: { a, b, c } → { 1, 2, 3 }
be defined by f(a) = f(b) = 1
and f(c) = 2
.
Then map(f)
applied to the list <a, b, c, a>
can be calculated as follows:
map(f)(<a, b, c, a.>) = <f(a), f(b), f(c), f(a)> = <1, 1, 2, 1>
.
.
.
We have map(f:A → B): [A] → [B]
or, in curry form map: (A → B) → [A] → [B]
which we shall see in a moment. ;-)
These definitions are from this book, Discrete Structure, Logic, and Computability
.
ที่มาที่ไปขà¸à¸‡ gist นี้: https://www.linkedin.com/posts/sila-setthakan-anan_maths4workingprogrammers-activity-6997207193452257280-og4i
Composition Function Reference: https://www.aplustopper.com/composition-functions-f-o-gx
by the way, just note.
High school's student may have seen Higher-Order Function before...
h
is a function that take function g
and return function f
More Example: if term