Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Functional Mix

Total questions: 26

Worksheet time: 23mins

Name
Class
Date
1.

This question is based on the function isEqual, that finds whether two numbers are equal or not.

What is the function's type signautre?

a)

isEqual : : Bool ->Int -> Int

b)

isEqual : : Int -> Bool

c)

isEqual : : Int -> Int -> Bool

2.

This question is based on function isEqual, that finds whether two numbers are equal or not. What is the function code?

a)

isEqual a b = a == b

b)

isEqual a b == a = b

c)

isEqual a b = a = b

d)

isEqual a ==b = a b

3.

This question is based on functions f(x) = x-1 and g(x) = x^2-1.
What is g o f?

a)

x^2

b)

x^2 - 2x

c)

x^2-x

d)

x^2+2x

4.

This question is based on functions f(x) = x-1 and g(x) = x2-1.
What is g o f (3)?

a)

1

b)

3

c)

5

d)

9

5.

What is the result obtained when this code is executed?
num = [10, 20, 30, 40]

add3 a = a + 3

map (add3) num

a)

[13, 20, 30, 40]

b)

[13, 23, 33, 43]

c)

100

d)

103

6.

fruits = [“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is the result obtained when this statement is executed?
tail(tail(fruits))

a)

“Pear”

b)

“Kiwi”

c)

“Honeydew”, “Watermelon”, “Kiwi”, “Pear”

d)

“Watermelon”, “Kiwi”, “Pear”

7.

fruits = [“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is the result obtained when this statement is executed?
length fruits

a)

5

b)

4

c)

3

d)

2

8.

fruits = [“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]
What is the result obtained when this statement is executed?
fruits ++ [“Banana”]

a)

[“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”, “Banana”]

b)

[“Banana”, “Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]

c)

[“Apple”, “Honeydew”, “Watermelon”, “Kiwi”, “Banana”]

d)

[“Banana”, “Honeydew”, “Watermelon”, “Kiwi”, “Pear”]

9.

What is a programming paradigm?

a)

A style of programming

b)

A type of software

c)

A hardware component

d)

A debugging tool

10.

Which programming paradigm is based on the concept of functions and avoids changing-state and mutable data?

a)

Procedural

b)

Object-Oriented

c)

Declarative

d)

Functional

11.

What does a functional program describe?

a)

A series of functions

b)

A series of variables

c)

A series of loops

d)

A series of classes

12.

Functional programming is very useful for programs where we need:

a)

Side-effects

b)

Immutability

c)

Procedures

d)

Recipes

13.

Which of the following is NOT a benefit of functional programming?

a)

Expressing pure mathematical functions

b)

Higher-order abstractions

c)

Procedures

d)

Programs with no side-effects

14.

How is the function to square a number written in Haskell?

a)

squareNumber(x) = x * x

b)

squareNumber x = x * x

c)

squareNumber x = x ** 3

d)

squareNumber(x) = x // 2

15.

What is the domain in the context of functions?

a)

A. A set from which the function’s output values are chosen

b)

B. A set from which the function’s input values are chosen

c)

C. A mapping from a set of inputs to a set of possible outputs

d)

D. A set of all possible outputs

16.

What is the co-domain in the context of functions?

a)

A. A set from which the function’s input values are chosen

b)

B. A set from which the function’s output values are chosen

c)

C. A mapping from a set of inputs to a set of possible outputs

d)

D. A set of all possible inputs

17.

What is a function in the context of mathematics?

a)

A. A set from which the function’s input values are chosen

b)

B. A set from which the function’s output values are chosen

c)

C. A mapping from a set of inputs, called the domain, to a set of possible outputs, known as the co-domain

d)

D. A set of all possible inputs

18.

In the function notation F: A -> B where f(x) = x * 2, what does 'A' represent?

a)

Co-domain

b)

Domain

c)

Output

d)

Function

19.

What feature of Haskell enables higher performance code by default?

a)

Object-oriented design

b)

Dynamic typing

c)

Statelessness and Immutability

d)

Extensive libraries

20.

What are higher order functions in Haskell?

a)

Functions that only take other functions as arguments

b)

Functions that can only be used with integers

c)

Functions that can take other functions as arguments or return functions as results

d)

Functions that cannot return functions as results

21.

Function g( ) is defined by the vector: {(2,10),(3,12),(4,14),(5,16)}

What is the value g(4)?

a)
g(4) = 4
b)
g(4) = 16
c)
g(4) = 10
d)
g(4) = 14
22.

Consider the following function expressed as a vector { (3,11), (4,18), (5,27), (6,38) } 

What is the domain?

a)
{4,11,5,18}
b)
{3,11,4,18}
c)
{3,4,5,6}
d)
{11,18,27,38}
23.
Find the head of this list
myList = [2, 3, 67, 89, 4]
a)
2
b)

[3, 67, 89, 4]

c)

[2, 3, 67, 89]

d)

[2]

24.

Evaluate the following:

filter (>=3) [1, 19, 17, 3, 8, 2]

a)

[19, 17, 3, 8]

b)

[19, 17, 8]

c)

[1, 19, 17, 3, 8, 2]

d)

[1, 3, 2]

25.

Evaluate the following:

head (reverse (map (*2) [2, 3, 4]))

a)

[4, 6, 8]

b)

4

c)

8

d)

[8, 6, 4]

26.

First-class functions can be... (PICK 3)

a)

passed as arguments to other functions

b)

returned from other functions

c)

assigned to variables

d)

partially applied

e)

given named parameters