Lesson 4.12.1.1

4.12.1.1 Function types and first-class objects Quiz: AQA Computer Science, Unit 12

20 questions

In partnership with Revision Ninja

Lesson 4.12.1.1, Function types and first-class objects: 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.

Host this setFree Play

The 20 questions

  1. In f: A -> B, what is A called?

    • The co-domain, the set from which the function's output values are chosen.
    • The domain, the set from which the function's input values are chosen.
    • The range, the set of every output value that the function actually produces.
    • The argument list, which must always contain a single integer value.
  2. In f: A -> B, what is B called?

    • The argument type, which is always the same as the input type of the function.
    • The first-class object that the function returns to its caller at the end.
    • The domain, the set of inputs that the function is allowed to accept.
    • The co-domain, the set from which the function's output values are chosen.
  3. What does f: A -> B mean?

    • f is a function whose argument type is A and whose result type is B.
    • f is a variable that stores the values of A and B combined in one structure.
    • f is a list of all the values in A that map to values of B in a table.
    • f takes B as its input and always produces A as its output in every call.
  4. Which statement about the co-domain is correct?

    • The co-domain is always the same set as the domain of the function.
    • Not all members of the co-domain need to be outputs of the function.
    • Every member of the co-domain must be produced as an output of the function.
    • The co-domain must contain only integers, whatever the function computes.
  5. For f: {a,...,z} -> {0,...,25}, which maps a to 0, b to 1, and so on, what is the domain?

    • The set of positive integers that are greater than 25.
    • The set of integers from 0 to 25 inclusive.
    • The set of all words that can be made from the letters a to z.
    • The set of letters a to z.
  6. A function add takes two integers and returns an integer, with type integer x integer -> integer. What is its argument?

    • Two separate integers passed through two different argument slots in turn.
    • A single pair of integers, such as (3,4).
    • A list of all the integers that are less than the result of the addition.
    • A single integer that is the sum of the two inputs given to the function.
  7. What does function application mean?

    • Returning a function from another function as the only result of the call.
    • Storing a function in a variable so that it can be reused later in a program.
    • Creating a new function by combining two existing functions into one.
    • Applying a function to its arguments, for example add(3,4).
  8. What is the type of the function f(x) = x + 2 on the integers?

    • integer -> integer
    • string -> integer
    • integer x integer -> integer
    • real -> boolean
  9. Which of these is an example of a first-class object?

    • A function that is assigned to a variable and then passed into another function as an argument.
    • A keyword such as if, which cannot be stored in a variable or passed anywhere.
    • A syntax rule that is applied only while the program is being compiled.
    • A comment in the source code, which is removed before the program runs.
  10. Why is a function a first-class object in a functional language?

    • Because the compiler assigns every function a unique number that is fixed for life.
    • Because it can be an argument to another function as well as the result of a function call.
    • Because functions can be used only inside the program module that defines them.
    • Because functions are stored only in separate files and are never actually executed by the runtime, so they cannot be passed around at all.
  11. Which of these is a first-class value in many programming languages?

    • A label that is used only to name a block of code for jump instructions.
    • A comment in the program source, which the compiler ignores completely.
    • An integer, which can be assigned to a variable and returned from a function.
    • A loop structure, which cannot appear inside an expression anywhere in the program.
  12. f: integer -> boolean is defined by f(x) = x > 0. What is the co-domain of f?

    • boolean
    • integer
    • integer x boolean, which is the pair of the input and output types.
    • The set of integers that are greater than zero only in each case.
  13. A function g maps days of the week to the integers 1 to 7, with Monday giving 1. What is the domain of g?

    • The set of all calendar dates that occur in a single year of the calendar.
    • The set containing both the days of the week and the integers from 1 to 7.
    • The set of integers from 1 to 7 used to name each day.
    • The set of days of the week.
  14. Evaluate: a function has domain {1,2,3} and co-domain {a,b,c,d}, with 1 -> a, 2 -> b and 3 -> a. Which statement is true?

    • The function is valid only if d is also one of the outputs produced by the function.
    • The function is invalid, because the co-domain has more members than the domain.
    • The function is valid, and d is in the co-domain but is not used as an output.
    • The function is invalid, because two inputs map to the same output value.
  15. A function h has type string -> integer. What must it do with each string it receives?

    • Map each integer to a string in the domain of the function h.
    • Return a list of every string that the function has received so far, in the order that the strings arrived at the function.
    • Map each string in its domain to exactly one integer in its co-domain.
    • Return a boolean value that says whether the string is empty or not.
  16. Which statement is true of any function f: A -> B?

    • Elements of B that are never used as outputs are removed from the type of f.
    • Each element of B is mapped to exactly one element of A in every case.
    • Each element of A is mapped to exactly one element of B.
    • Each element of A may be mapped to any number of elements of B by the function.
  17. A function f: {1,2,3} -> {0,...,6} is defined by f(x) = 2x. Which set is the set of outputs actually produced?

    • {2, 4, 6, 8}
    • {1, 2, 3}
    • {0, 1, 2, 3, 4, 5, 6}
    • {2, 4, 6}
  18. A function reads a character and returns its position in the alphabet. What is its type?

    • char -> integer
    • char x char -> integer
    • string -> string
    • integer -> char
  19. Why can a function with type A -> B never produce an output outside B?

    • Because values in B are always stored as integers in memory, which limits them.
    • Because B is the co-domain, which defines the set from which all outputs must be chosen.
    • Because the compiler removes every value that does not match the type of the first argument.
    • Because outputs are always restricted to the domain A by the compiler at runtime.
  20. Which statement about first-class functions in Python is correct?

    • Only Haskell supports first-class functions among the languages named in the specification.
    • A Python function must always return an integer, so it cannot be treated as a value.
    • A Python function cannot be stored in a variable, so it is never a first-class object.
    • A Python function can be passed as an argument, which makes it a first-class object in that language.

All AQA Computer Science quizzes