Functional programming Flashcards
Function definition
A rule that for, for each element in some set A of inputs, assigns an output chosen from set B, but whithout necessarily using every member of B.
Define an argument
A piece of data that is passed to a function, and the rule is applied to the argument, creating the return value.
What is applied to the argument after it is passed to a function?
The rule
What possible forms could an argument take?
A number (pos, neg, decimal) Character Or any other data type. Another function if the language supports it.
Concerning using an argument as another function, what will the function need to do?
Will specify what data type is required for the argument.
If f is the function, A is the input and B is the output, define the function type
f : A -> B
In the function type F : A -> B what is A?
The argument type
In the function type F : A -> B what is B? What is A?
What does this mean?
B = The result type. A = the argument type
This means that function f maps A to B.
What do we describe the set of inputs (A) (the argument) as?
The domain.
Whaf do we describe the set of outputs (B (the return type) as?
The co-domain.
What must we remember about co-domains?
Not all members of the co-domain have to be used as outputs.
how can functionalities of f be changed?
If f has a different function type
First class object definition
Objects which may: appear in expressions Be assigned to a variable Be assigned to arguments Be returned in function calls
What are functions known as in functional programming?
First class objects.
What do some imperative languages support? What does this mean?
Functions as first class objects.
Functions can be passed as arguments or returned as the result of another function.
Outline examples of first class objects
Integers
Floating point values
Characters
Strings
Define function application
Applying the function rule to the arguments of the function
How many arguments do functions take in functional programming?
One - (3,5 = a pair = one).
What is a partial function
Takes advantage of the inability of a function to take more than one input.
Outline arguments in a partial function
One of the arguments is fixed, leading to a more restricted, specialised function.
What is functional composition
The act of combining two functions to create a new function.
What is the benefit of a function composition?
The user is able to use the functions both seperately and in conjunction.
What is the condition that must be met for two functions to be combined?
As long as domain of one of the functions is the same as the co-domain of the other.
Symbol that imdicates two functions are being combined
○