WorksheetsFunctional Mix
Total questions: 26
Worksheet time: 23mins
This question is based on the function isEqual, that finds whether two numbers are equal or not.
What is the function's type signautre?
isEqual : : Bool ->Int -> Int
isEqual : : Int -> Bool
isEqual : : Int -> Int -> Bool
This question is based on function isEqual, that finds whether two numbers are equal or not. What is the function code?
isEqual a b = a == b
isEqual a b == a = b
isEqual a b = a = b
isEqual a ==b = a b
This question is based on functions f(x) = x-1 and g(x) = x^2-1.
What is g o f?
x^2
x^2 - 2x
x^2-x
x^2+2x
This question is based on functions f(x) = x-1 and g(x) = x2-1.
What is g o f (3)?
1
3
5
9
What is the result obtained when this code is executed?
num = [10, 20, 30, 40]
add3 a = a + 3
map (add3) num
[13, 20, 30, 40]
[13, 23, 33, 43]
100
103
fruits = [“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is the result obtained when this statement is executed?
tail(tail(fruits))
“Pear”
“Kiwi”
“Honeydew”, “Watermelon”, “Kiwi”, “Pear”
“Watermelon”, “Kiwi”, “Pear”
fruits = [“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is the result obtained when this statement is executed?
length fruits
5
4
3
2
fruits = [“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is the result obtained when this statement is executed?
fruits ++ [“Banana”]
[“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”, “Banana”]
[“Banana”, “Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
[“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Banana”]
[“Banana”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is a programming paradigm?
A style of programming
A type of software
A hardware component
A debugging tool
Which programming paradigm is based on the concept of functions and avoids changing-state and mutable data?
Procedural
Object-Oriented
Declarative
Functional
What does a functional program describe?
A series of functions
A series of variables
A series of loops
A series of classes
Functional programming is very useful for programs where we need:
Side-effects
Immutability
Procedures
Recipes
Which of the following is NOT a benefit of functional programming?
Expressing pure mathematical functions
Higher-order abstractions
Procedures
Programs with no side-effects
How is the function to square a number written in Haskell?
squareNumber(x) = x * x
squareNumber x = x * x
squareNumber x = x ** 3
squareNumber(x) = x // 2
What is the domain in the context of functions?
A. A set from which the function’s output values are chosen
B. A set from which the function’s input values are chosen
C. A mapping from a set of inputs to a set of possible outputs
D. A set of all possible outputs
What is the co-domain in the context of functions?
A. A set from which the function’s input values are chosen
B. A set from which the function’s output values are chosen
C. A mapping from a set of inputs to a set of possible outputs
D. A set of all possible inputs
What is a function in the context of mathematics?
A. A set from which the function’s input values are chosen
B. A set from which the function’s output values are chosen
C. A mapping from a set of inputs, called the domain, to a set of possible outputs, known as the co-domain
D. A set of all possible inputs
In the function notation F: A -> B where f(x) = x * 2, what does 'A' represent?
Co-domain
Domain
Output
Function
What feature of Haskell enables higher performance code by default?
Object-oriented design
Dynamic typing
Statelessness and Immutability
Extensive libraries
What are higher order functions in Haskell?
Functions that only take other functions as arguments
Functions that can only be used with integers
Functions that can take other functions as arguments or return functions as results
Functions that cannot return functions as results
Function g( ) is defined by the vector: {(2,10),(3,12),(4,14),(5,16)}
What is the value g(4)?
Consider the following function expressed as a vector { (3,11), (4,18), (5,27), (6,38) }
What is the domain?
myList = [2, 3, 67, 89, 4]
[3, 67, 89, 4]
[2, 3, 67, 89]
[2]
Evaluate the following:
filter (>=3) [1, 19, 17, 3, 8, 2]
[19, 17, 3, 8]
[19, 17, 8]
[1, 19, 17, 3, 8, 2]
[1, 3, 2]
Evaluate the following:
head (reverse (map (*2) [2, 3, 4]))
[4, 6, 8]
4
8
[8, 6, 4]
First-class functions can be... (PICK 3)
passed as arguments to other functions
returned from other functions
assigned to variables
partially applied
given named parameters
