4.12 Fundamentals of Functional Programming Flashcards
What is meant by first class objects
are objects which may:
appear in expressions
be assigned to a variable
be assigned as arguments
be returned in function calls.
What is meant by function application
The process of giving particular inputs to a function
What is the domain and co domain of a function
domain - a set from which the function’s input values are chosen.
codomain - a set from which the function’s output values are chosen
What is partial function application
Partial function application is a concept where a function that takes multiple arguments is applied to some of its arguments, resulting in a new function that takes the remaining arguments.
What is composition of functions
Combing two functions to get a new function
What are Higher-order functions.
A function is higher-order if it takes a function as an argument or returns a function as a result, or does both.
what does the map function do
map is the name of a higher-order function that applies a given function to each element of a list, returning a list of results.
what does the filter function do
filter is the name of a higher-order function that processes a data structure, typically a list, in some order to produce a new data structure containing exactly those elements of the original data structure that match a given condition.
what does the reduce or fold function do
reduce or fold is the name of a higher-order function which reduces a list of values to a single value by repeatedly applying a combining function to the list values.
How do functional programmers define lists
As a concatenation of a head and a tail
what is the head of a list
Head: The first element of the list.
what is the tail of a list
Everything after the first element — the rest of the list.
How do you return the head of list
use of index, eg, print list[0]
How do you return tail of list
tail = list[1:]
How do you test for empty list
use len function
How do you return length of list
use len function
How do you construct an empty list
list = []
How do you prepend an item to a list
new_list = [1] + list
How do you append an item to a list.
list.append(value) or list.extend(value)
Haskell and Lisp are both types of what programming paradigm?
functional programming languages.
If the domain of the function below is {1, 2, 3}, what is the co-domain?
func x = x * 3
{3, 6, 9}
what is meant by a variable that is immutable?
Variables cannot be reassigned once they are given a value
Functional programming is stateless and has no side effects. what does this mean?
The state of memory does not change, i.e. the values of variables stay the same. Therefore there is no record of previous operations and each operation is processed using only the arguments/parameters provided will always return the same result for a given input and so cannot affect other operations within the program.
what does 5:[1,2,3] do in haskell
creates a new list with 5 at the front