4.12 - Fundamentals of functional programming Flashcards
What is a function?
A rule that, for each element in some set A of inputs, assigns an output chosen from set B, but without necessarily using every member of B.
What is an argument?
A piece of data passed into a function.
What is a first class object?
An object which may:
- Appear in expressions
- Be assigned to a variable
- Be assigned as an argument
- Be returned in function calls
What are functions in functional programming?
First-class objects
What is function application?
Applying a function rule to the arguments of the function
What is partial function application?
One of the arguments is fixed, leading to a more restricted specialised function.
What is composition of functions?
The act of combining two functions to create a new function. User is able to use functions both separately, and in conjunction. Domain of one must be same as co-domain of the other.
What are higher order functions?
Either take function as an argument, return function as a result, or both.
What does the map function do?
Takes a second function and applies it to a list of elements before returning the new list.
What does the filter function do?
Returns elements of a list which adhere to condition given.
What does the fold function do?
Reduces list to a single value. It needs an operator (+,- etc), a starting number, and a list. The type of fold (left or right) determines how the recursion will work.
What does the prepend operator do?
It has the symbol : and is used to add items to the front of a list.
It is used in the format
item : list
What does the append operator do?
It has the symbol ++ and is used to add items to the rear of a list.
It is used in the format
item ++ list
How do you find if a list is empty?
null listname
How do you find the length of a list?
length listtname