- [Points 2]
Which of the following best describes a trait specific to functional
programming languages? Pick only one answer.
- They have polymorphic typing.
- They make extensive use of state and side-effects.
- They have garbage collectors.
- They treat functions as first-class values.
- [Points 3]
The following code describes a function in SML.
fun g nil = true
| g (x::y::k) = g k;
What function is computed by g?
- The function that takes a list and returns true if the
list is an even length and false if the list is an odd length.
- The function takes a list and always returns true.
- It does not define a function since it causes a type error.
- The function is not defined for all lists since it does not have
exhaustive patterns.
- [Points 2]
What is the value computed for the following expression? 28
let val x = 3
in let val x = 5
in x * x
end
+ x
end;
- [Points 3]
What happens when SML is given the following code?
fun f 0 = 0
| f n = f(n - 1) - 1;
- Defines a function which when applied to an integer, returns the
modulo of that integer.
- Defines a function which when applied to a non-negative
integer n, returns the negative of n.
- Gives a type error.
- Defines a function that gives a runtime error when applied to 1.