AQA A Level · Computer Science 7517

Writing functional programs: แบบฝึกหัด

ข้อปรนัย 5 ข้อ ตรวจให้ทันทีที่ตอบ และข้อเขียน 5 ข้อ พร้อมวิธีทำละเอียด ทั้งหมดจากเรื่อง Writing functional programs

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 วินาที

อยากฝึกโจทย์แบบนี้เพิ่มไหม เริ่มฝึกหัวข้อนี้ได้เลย ตรวจให้ทันทีทุกข้อ

เริ่มฝึกเลย