- [Points 2]
Which of the following best describes a trait specific to functional
programming languages? Pick only one answer.
- They have strong typing.
- They treat functions as first-class values.
- They have garbage collectors.
- They make extensive use of objects and methods.
- [Points 3]
The following code describes a function in SML.
fun g nil = 1
| g ((x,y)::k) = (x + y) * (g k);
What function is computed by g?
- The function takes a list and always returns 0.
- The function that takes a list of pairs of numbers and returns the
product of the sum of the pairs.
- It does not define a function since it causes a type error.
- It does not define a function since it causes a match exception error.
- [Points 2]
What is the value computed for the following expression? 14
let val z = 5
in let val z = 3
in z * z
end
+ z
end;
- [Points 3]
What happens when SML is given the following code?
fun f 0 = 0
| f n = n * f(n - 1);
- Gives a type error.
- Defines a function which when applied to a non-negative
integer n, returns the value 0.
- Defines a function that gives a runtime error when applied to 1.
- Defines the factorial function.