AQA A Level · Computer Science 7517

撰寫函數式程式:練習題

5 條多項選擇題即時批改,另有 5 條文字題附完整解題步驟,全部圍繞「撰寫函數式程式」。

10 條題目25 免費,無需登記
第 1 題
1

In Haskell, given the list [10, 20, 30], what is the tail of this list?

第 2 題
1

What is the result of the following function composition?
Let \(f(x) = x + 1\) and \(g(x) = x^2\).
Find \((g \circ f)(3)\).

第 3 題
1

Given the following Haskell-style list definition:
myList = [x * 2 | x <- [1..5], x > 2]

What is the final value of myList?

第 4 題
1

In a functional language like Haskell, if a list is defined as [7, 2, 9], what are the head and tail of this list respectively?

第 5 題
1

Which functional programming operation is best described as reducing a list of values to a single value by repeatedly applying a combining function?

第 6 題
2

Identify the result of applying the list operation tail to the Haskell list \([10, 20, 30]\).

先自己寫一次答案,再對照解題步驟。

第 7 題
3

Explain the difference between a higher-order function and a standard first-order function.

先自己寫一次答案,再對照解題步驟。

第 8 題
5

A list is represented in Haskell notation as head:tail. If a list is defined as \(L = [7]\), state the values of the head and the tail.

先自己寫一次答案,再對照解題步驟。

第 9 題
3

Describe the purpose of the following higher-order functions commonly used in functional programming:

(a) map
(b) filter
(c) reduce (also known as fold)

先自己寫一次答案,再對照解題步驟。

第 10 題
7

A high-order function foldright (or reduce) is defined. It takes a combining function \( f \), an initial value \( z \), and a list.

Let \( f(x, acc) = x - acc \) and the initial value \( z = 0 \).

(a) Calculate the result of applying this fold operation to the list \( [5, 10, 15] \) using right-associativity: \( f(5, f(10, f(15, 0))) \).
(b) Explain how the result would differ if left-associativity (foldleft) was used with the same function and initial value: \( f(f(f(0, 5), 10), 15) \).
(c) Why is the choice of associativity important for non-commutative operations like subtraction?

先自己寫一次答案,再對照解題步驟。

* thinka提供的內容由AI生成,可能並非總是準確或最新。請將其用作輔助資源,並與官方材料進行核實。

你已看過標準答案,接下來輪到批改你的答案。

這一頁可以告訴你好答案的樣子,卻無法指出你的答案欠缺什麼。thinka 按真實評分準則批改你的文字答案,約 15 秒完成。

想多做幾條同類題目?立即開始練習呢個課題,即做即批改。

立即練習