Fundamentals of Functional Programming Flashcards
What is a function?
A rule that assigns an output from set B to each element in set A, without necessarily using every member of B.
Which of the following is not true of
first-class objects?
1. They can appear in expressions
2. They can be assigned to a data type
3. They can be assigned as arguments
4. They can be returned in function calls
They can be assigned to a data type
What is an argument in relation to a function?
An argument is a piece of data passed to a function for processing.
What does the DoubleMe function do?
DoubleMe takes an input and outputs its double. For example, DoubleMe 6 returns 12.
What is a function type?
A function type describes the argument type and result type of a function. It specifies the domain and co-domain of the function.
Provide an example of a function type.
The function f returns double the input. The domain is the set of natural numbers, and the co-domain is the set of even natural numbers.
What does it mean for functions to be first-class objects?
First-class objects can appear in expressions, be assigned to variables, be passed as arguments, and be returned as function results.
What is function application?
Function application is the process of applying the function rule to the arguments to obtain the output.
Explain partial function application.
Partial function application fixes one or more arguments of a function, creating a specialized version of the function.
What is functional composition?
Functional composition is the act of combining two functions to create a new function by connecting the output of one function to the input of another.
Can any two functions be composed together?
: Two functions can be composed if the domain of one function matches the co-domain of the other function.
What are higher-order functions?
Higher-order functions either take a function as an argument, return a function as its result, or both.
What is the map function?
The map function applies a second function to each element in a list and returns a new list with the transformed elements.
What is the filter function?
The filter function returns the elements of a list that satisfy a given condition.
What is the fold function?
The fold function, also known as reduce, combines the elements of a list into a single value using an operator and an initial value.