Quiz 3

One-page version suitable for printing.

Statistics:

mean     21.909 (241.000/11)
stddev   5.648
median   23.000
midrange 17.750-25.000

#   avg
1   7.73 / 10
2   4.36 / 10
3   7.82 / 10
 + 2-point bonus

Question 3-1

Write a Haskell function countZeroes that takes a list of integers as a parameter and returns the number of zeroes contained in the list. For example, if I called countZeroes [5,0,0,8,0], it should return 3, since the list contains three zeroes.

Solution

Question 3-2

Write a Haskell function named doubleFunc which takes as its parameter a function f from integers to integers and returns a function from integers to integers which is always twice f. For example, using this function I should be able to do the following.

f x = x + 5
g x = 3 * x
fd = doubleFunc f
gd = doubleFunc
With these definitions, fd 3 should return 2 f(3) = 2 (3 + 5) = 16$ and gd 10 should return 2 (3 * 10) = 60.

Solution

Question 3-3

Reduce the following lambda expression, showing your intermediate steps. It should reduce to a number.

(λf.λa.f(a + 3) - (f a) - (f 3)) (λx.x * x)) 7

Solution