4.12 Fundamentals of Functional Programming Flashcards
(15 cards)
What is a function
a rule for each element in some set A of inputs (domain), assigns an output chosen from set B (co-domain), but without necessarily using every member
How does a function work
An argument is passed to a function, the rule is applied to the argument, creating the return value output
What is a higher-order function
a function that takes a function as an argument or returns a function as a result, or does both
what are first class objects
objects which may
- appear in expressions
- be assigned to a variable
- be assigned as arguments
- be returned in function calls
what are some first-class objects
integers, floating-point values, characters, strings and functions
what does a function being a first class object mean
it can be passed as arguments or returned as the result of another function
what does function application mean
giving particular inputs to a function
what is a partial function application
one of the arguments is fixed, leading to a more restricted specialised function
what is meant by composition of functions and the benefit
combines two functions to create a new function - users are able to use the function both separately and in conjunction
criteria for functions that can be combined
the domain of one of the functions is the same as the co domain of the other
what order would you do these functions in g ○ f
f is applied first and then g is replied to the result
what is the map function
it is a higher-order function that applies a given function to each element of a list, returning a list of results
what is the filter function
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 is the reduce or fold function
a higher order function which reduces a list of values to a single value by repeatedly applying a combining function to the list values
describe the head and tail of
a list and what is the head and tail of the list [3,4,5]
head - first value of the list - 3
tail - list containing all values except for the first element - [4,5]