0% found this document useful (0 votes)
97 views7 pages

12.1 - Functional Programming Paradigm

The document consists of an exam paper focused on functional programming, with questions covering concepts such as higher-order functions, list operations, and domain name servers. It includes specific function calls and requires students to explain their reasoning and calculations. Additionally, it provides mark schemes and examiner reports detailing student performance and common misconceptions.

Uploaded by

opuzrodin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views7 pages

12.1 - Functional Programming Paradigm

The document consists of an exam paper focused on functional programming, with questions covering concepts such as higher-order functions, list operations, and domain name servers. It includes specific function calls and requires students to explain their reasoning and calculations. Additionally, it provides mark schemes and examiner reports detailing student performance and common misconceptions.

Uploaded by

opuzrodin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

_______________________

Name:
_
12.1 Functional
programming paradigm _______________________
Class:
_

_______________________
Date:
_

Time: 20 minutes

Marks: 14 marks

Comments:

Page 1 of 7
Q1.
In a functional programming language a function named square and three lists a, b and c
are defined as follows.

square x = x * x

a = [1, 3, 5]
b = [1, 5, 10, 15]
c = [9, 7, 2]

(a) What is the list or value that is the result of applying the functions head(tail(tail
b))?

___________________________________________________________________
(1)

(b) Calculate the results of making the function calls listed in Table 1 with the lists a, b
and c above.

Table 1

Function Call Result


map square a

filter (<10) b

fold (+) 0 c

(3)

(c) map is an example of a higher-order function.

Explain what a higher-order function is.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(1)
(Total 5 marks)

Q2.
In a functional programming language, a recursively defined function named map and a
function named double are defined as follows:

map f [] = []
map f (x:xs) = f x : map f xs

double x = 2 * x

Page 2 of 7
The function x has two parameters, a function f, and a list that is either empty (indicated
as []), or non-empty, in which case it is expressed as (x:xs) in which x is the head and
xs is the tail, which is itself a list.

(a) In Table 1, write the value(s) that are the head and tail of the list
[ 1, 2, 3, 4 ].

Table 1

Head

Tail

(b) The result of making the function call double 3 is 6.


(1)

Calculate the result of making the function call listed in Table 2.

Table 2

Function Call Result


map double [ 1, 2, 3, 4
]

(1)

(c) Explain how you arrived at your answer to part (b) and the recursive steps that you
followed.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(3)
(Total 5 marks)

Q3.
(a) Put one tick on each row of the table below to classify each of (i), (ii) and (iii) as
either a URL, a Domain Name, an IP address or a Protocol.

URL Domain IP Address Protocol


Name

(i) http://

Page 3 of 7
www.guineas.co.uk

(ii) 212.58.251.195

(iii) guineas.co.uk
(3)

(b) What is the purpose of a Domain Name Server on the Internet?

___________________________________________________________________

___________________________________________________________________
(1)
(Total 4 marks)

Page 4 of 7
Mark schemes

Q1.
(a) Marks is for AO2 (apply)

10;
A. [10] this time
1

(b) Mark is for AO2 (apply)

Function Call Result


map square a [1,9,25]
filter (<10) b [1,5]
fold (+) 0 c 18

1 mark for each correct response in the Result column.


I. Missing brackets this time or use of incorrect type of brackets
I. If returned values are assigned to new lists eg x = [1,9,25]
A. [5,1] for row 2 this time
3

(c) Mark is for AO1 (knowledge)

A function that takes a function as an argument // returns a function as a result


// takes a function as an argument and returns a function as a result;
A. “Parameter”, “Input” for “Argument”
NE. A function that uses another function
R. Explanations that are specifically of the map function
1
[5]

Q2.
(a) Marks is for AO1 (understanding)

Head 1

Tall [2,3,4]

1 mark for both head and tail correct.


I if brackets are missing in tail.
1

(b) Mark is for AO2 (apply)

[ 2, 4, 6, 8 ];

I if brackets are missing in tail.


1

(c) All marks AO1 (understanding)

Page 5 of 7
1 mark: Explaining that map applies the function double to each list element;
1 mark: Explaining that map applies double to the head of the list;
1 mark: and then a recursive call is made on the tail of the list;
3
[5]

Q3.

(a)
Domain
URL IP Address Protocol
Name

(i)

http://www.guineas.co.uk

(ii) 212.58.251.195 ✔

(iii) guineas.co.uk ✔

1 mark for each correctly placed tick

R Answers with more than one tick on a row.


3

(b) To translate/convert/resolve domain names into IP addresses;


A FQDN for domain name
Answer must have the CONCEPT of an action
NE To store the domain names and IP Addresses
NE To access the web page without knowing the IP address
NE To link the domain name to the IP address
1
[4]

Page 6 of 7
Examiner reports

Q1.
(a) This question was moderately well answered with just over half of students correctly
identifying that the result of applying the functions was 10. Some students gave the
result as [10], which was accepted this year. Students should be aware however
that, when the output of the head function should be a single value, we will not
accept answers expressed as lists in the future. The most common incorrect
response was 15.

(b) The purposes of the map and filter functions were fairly well understood with two
thirds of students achieving two or more of the three marks, but the purpose of the
fold function was less well known. The most common incorrect response with
regard to filter was [10, 15] which suggested that students had either confused <
and > or that they believed the filter function filtered numbers out of the result
rather than filtering them into it. fold was poorly understood. Many students either
gave the original list as the output or simply appended the 0 to the original list to
generate the output. Marks were only awarded for fold if the result was expressed
as a single value rather than a list containing a single value as the fundamental
purpose of this application of the fold operation was to combine the list into one
single value.

(c) The term “higher-order” function was not well understood with only just over a
quarter of students correctly identifying that a higher-order function would take
another function as an argument or return a function as a result. Responses that a
higher-order function would use other functions were not considered mark worthy as
this description could be applied to many functions. Other common mistakes were to
believe that a higher-order function was simply more important than some other
functions or to confuse one with a built-in function in a procedural language.

Q3.
Part (a) was very successfully answered. The vast majority of candidates could distinguish
between an IP address, Domain Name and URL and gained full marks. Only a handful of
candidates failed to score any marks.

For part (b) many candidates had some idea what a Domain Name Server (DNS) did but
often described this poorly. The majority simply stated that it stored the appropriate URL
and IP address combinations and left it at that, they did not go on to mention its active role
in translating the URL into an IP address. Common incorrect answers were of the form
that the Domain Name is easier to remember than an IP address. There was also a lot of
confusion about the DNS being the preferred way of ensuring all web servers etc. had a
unique URL so servers would be able to find requested sites i.e. candidates were
describing Domain Name Registration services.

Page 7 of 7

You might also like