Functional programming paradigm: A function (f) has a type ( f: A -> B ),
where (A) is the argument type (The set from which the function's input
values are chosen) domain and (B) is the result type The set from which
the function's output values are chosen (not all members of the co-domain
need to be outputs) co-domain.
A function is considered a first-class object in functional programming
languages and in imperative programming languages that support such
objects. This means that functions can be: passed as arguments to other
functions, returned as results from function calls, assigned to variables
and used in expressions.
First class objects characteristics include: they can appear in expression,
assigned to variables, passed as arguments, returned in functional calls.
First class objects are integers, floating point values, characters, and
strings.
Function application refers to the process of applying a function to its
arguments. For example, add(3,4) represents the application of the
function add to the integer arguments 3 and 4. The type of this function
can be expressed as: “f= integer x integer -> integer”. Where “integer x
integer” is the Cartesian product of the set of integers with itself. Although
it seems like the function takes two arguments, it takes one argument,
which is a pair (e.g., (3,4)).
Partial function application refers to the process of fixing a few arguments
of a function, producing another function of fewer arguments. For
example, the function add takes two integers and returns an integer:
“add: integer -> (integer -> integer)” When you apply add to one
argument, such as add 4, it returns a new function that takes another
integer and adds 4 to it. This can be written as: “add: integer -> integer -
> integer”. Here, add is viewed as taking one argument at a time and
returning a function that takes the next argument, ultimately returning an
integer.
Example
Consider the function add: [add (x, y) = x + y]
Full Application: add (3, 4) returns 7.
Partial Application: add 4 returns a function that, when applied to
another integer, adds 4 to it. For example, (add 4) 3 returns 7.
This concept allows for more flexible and reusable code, as functions can
be partially applied and then completed later with additional arguments.
Functional Composition is the operation that combines two functions to
create a new function. Given two functions:
(f: A -> B)
(g: B -> C)
The composition of (g) and (f), denoted as (g.f), is a function whose
domain is (A) and co-domain is (C). This means that (f) is applied first, and
then (g) is applied to the result of (f).
A higher-order function is one that: takes one or more functions as
arguments, returns a function as its result, Or does both.