Lesson 4.12.1.4
4.12.1.4 Partial function application and composition of functions Quiz: AQA Computer Science, Unit 12
20 questions
In partnership with Revision Ninja
Lesson 4.12.1.4, Partial function application and composition of functions: 20 multiple choice questions for the AQA Computer Science (7517), Unit 12: Fundamentals of functional programming, written with Revision Ninja.
Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.
The 20 questions
-
What does partial function application mean?
- Giving a function fewer arguments than it takes, which returns a function that expects the remaining arguments.
- Running a function only for the part of a list that matches a given condition.
- Applying a function to all of its arguments and then discarding the result it returns.
- Splitting a function into two separate programs that run on different machines.
-
With add: integer -> integer -> integer, what does the expression add 4 return?
- A function which, when applied to an integer, adds 4 to that integer.
- An error, because add must always be called with two arguments in every case.
- A list containing the integers 4 and 4 as its two arguments.
- The integer 4, because add 4 simply returns its single argument unchanged.
-
If inc is add 4, what is the result of inc applied to 5?
- 20
- 9
- 4
- 5
-
In curried notation, what is the type of add that takes two integers?
- integer x integer -> integer
- integer -> integer -> integer
- integer -> integer x integer
- integer -> integer
-
What does the composition g o f mean?
- Store f and g in a list and apply them in a random order each time.
- Apply f first, then apply g to the result that f returns.
- Apply f and g to the same input and add the two results together.
- Apply g first, then apply f to the result that g returns.
-
For the composition g o f with f: A -> B and g: B -> C, what is the domain?
- The co-domain of g, which is C.
- The union of the domains of f and g combined together.
- The domain of f, which is A.
- The domain of g, which is B.
-
For f(x) = x + 2 and g(y) = y^3, what is g o f?
- (x + 2)^3
- (x^3) + 2 in every case
- x^3 + 2
- x + 8
-
Using f(x) = x + 2 and g(y) = y^3, what is (g o f)(1)?
- 27
- 5
- 9
- 7
-
Using f(x) = x + 2 and g(y) = y^3, what is (f o g)(1)?
- 27
- 3
- 4
- 5
-
Given inc x = x + 1 and double x = 2 * x, what is double (inc 3)?
- 6
- 7
- 8
- 10
-
Which expression is a partial application of a three-argument function f applied to a, b and c?
- f alone, which is a syntax error in every functional programming language.
- f a b, which returns a function that still expects the third argument.
- a, b and c applied in reverse order to produce a single value directly.
- f a b c, which returns a function that has no arguments left to take.
-
What does the curried form of a two-argument function allow?
- Calling it only from inside a loop structure within the same program module.
- Calling it with one argument at a time, with each call returning a function for the next argument.
- Calling it only once, with both arguments stored in a global variable first.
- Calling it with a list of arguments that are sorted into order before being used.
-
Evaluate: why is partial application useful in a functional program?
- It makes every function run faster by evaluating only half of its arguments at once.
- It allows a function to be written without any arguments in its definition at all.
- It prevents any function from ever returning a value to the caller of the function.
- It lets a general function be specialised, for example producing an add-four function that can be reused inside map.
-
f: A -> B and g: B -> C are functions. What is the composition g o f, and what is its domain?
- g o f, with domain A and co-domain C.
- f o g, with domain C and co-domain A, because the function applied first is the one whose output type is the result of the composition.
- g o f, with domain B and co-domain C.
- g o f, with domain B and co-domain A.
-
g o f is applied to 2, where f(x) = x + 2 and g(y) = y^3. Which steps happen in order?
- g(2) = 8 is computed first, then f(8) = 10 is computed.
- f(2) = 4 is computed, then f(4) = 6 is computed, then g(6) = 216.
- g(2) = 8 and f(2) = 4 are computed separately and multiplied together for 32.
- f(2) = 4 is computed first, then g(4) = 64.
-
f: integer -> boolean and g: boolean -> string are functions. What is the type of g o f?
- integer -> string
- integer x boolean -> string
- boolean -> integer
- string -> integer
-
Which description of composing functions in a functional language is correct?
- Running two functions in parallel and combining their outputs into a single list, which is always the same as applying one after the other.
- Passing the output of one function directly as the input to another, to create a new function.
- Copying the code of one function into the body of another in place of its name.
- Joining two strings together with a separator placed between them in the output.
-
Does g o f always give the same result as f o g?
- No, but only when the functions are defined on integers and not on real numbers.
- No, in general, because changing the order of application changes the result.
- Yes, because both functions are applied to the input at exactly the same time.
- Yes, because function composition is always commutative for real numbers.
-
Why does partial application fit the view add: integer -> (integer -> integer)?
- Because add returns two values at once, which are stored together in a pair.
- Because add is a list function that processes its arguments in order from the start.
- Because the function takes one argument and returns a new function that takes the next argument.
- Because add must always be called with both arguments, otherwise it returns nothing at all, which is why it can never be partially applied.
-
Which function results from partially applying multiply to 3, where multiply x y = x * y?
- A function that adds 3 to its argument, because the first argument is always added.
- The number 3, because a partially applied function returns its first argument unchanged.
- A function that needs two arguments and ignores the number 3 that was supplied.
- A function that multiplies its argument by 3.
Related quizzes
- Function types and first-class objects Quiz · 4.12.1.1 · 20 questions
- Writing functional programs Quiz · 4.12.2.1 · 20 questions
- List processing Quiz · 4.12.3.1 · 20 questions
- Data types Quiz · 4.1.1.1 · 20 questions
- Entity relationship modelling Quiz · 4.10.1.1 · 20 questions
- Big Data Quiz · 4.11.1.1 · 20 questions
- Analysis Quiz · 4.13.1.1 · 20 questions
- Data structures and abstract data types Quiz · 4.2.1.1 · 20 questions
- Breadth-first and depth-first search Quiz · 4.3.1.1 · 20 questions
- Problem-solving and algorithms Quiz · 4.4.1.1 · 20 questions