What is a function?
Rule that maps each element form a domain to a co-domain
What is a side-effect?
A change to the content / state around the function
What are the consequences of side effects?
Means that you cannot guarantee that a given function will provide exactly the same output form a given input
What is the image of a function?
Subset of values from the co-domain that are mapped as outputs
What are first-class objects?
Objects that:
- Can appear in expressions
- Can be assigned to variables
- Can be passed as an argument to another function
- Can be returned as a result of a function
Functions are first-class objects
What is function application?
The process of applying a function to its argument // described as the process of giving particular inputs to a function
How do you define a function in Haskell?
Declare the function’s type using a function signature and state the expressions that map inputs to outputs
Double :: Int -> Int
Double x = x * 2
What is a function’s type?
The set of values that form the functions domain and co-domain. If f:A->B is the function then A->B is the type
What is the function type of f : A -> B -> C
Type is A x B -> C where A x B is the cartesian product of the sets A and B.
What does f . g mean?
A new function composed of f and g where g is evaluated before f
When can two functions be composed?
If the codomain of the first matches the domain of the other
What is a partially applied function?
A function that requires multiple parameters but not all have been provided
Explain how the function add 4 5 is evaluated using partial function application
What must one pattern matching expression contain in order for no errors to occur?
A bound variable that ensures that the function has a mapping for every possible value in the domain
What is a list in functional programming?
Concatenation of a head and tail where the head is an element and a tail is another list
How do you return the head of the following list in Haskell: L = [1,2,3,4]
head L
How do you return the tail of the following list in Haskell: L = [1,2,3,4]
tail L
What does the map function do?
A function that applies a function to a list of items, returning a new list of results
What does the filter function do?
Applies a predicate function to a list of values, returning a new list of items that match the given criteria
What does the fold/reduce function do?
Reduces a list to a single value by recursively applying a combining function to each element in the list. A starting value for the combining function must be provided
What is a combining function?
A function that takes two arguments and returns a single value.
Why are functional programs paralelisable?
Describe how immutable data structures make programs parallelisable
Describe how statelessness can make programs parellisable