Writing Functional Programs

4.12.2 (8 questions). Public Notes: AQA's A Level Computer Science

For the list [4, 3, 5], return the head.

[4] The first element in the list is the head.

For the list [4, 3, 5] return the tail.

[3,5] Everything apart from the first element in the list is the tail.

State and explain is the result of null [].

True, this means the list is empty.

State and explain is the result of null [4, 3, 5].

False.

n = [1, 2, 3] /n n = n ++ [4, 5], what is the result of length[n].

Lists are immutable, the second line would return an error, while length[n] would be 3.

What is the result of Map (+1) {8, 11, 21}.

{9, 12, 22}.

What is the result of Filter (>4) {8, 2, 3, 7}.

{8, 7}.

What is the result of Foldl (+) {8,2,3,7}.

(((8+2)+3)+7) = 10+3+7 = 13+7 = 20.