- [Points 2]
Which of the following best describes a trait specific to functional
programming languages? Pick only one answer.
- They have strong typing.
- They make extensive use of state and side-effects.
- They have garbage collectors.
- They are organized around the mathematical notion of function and
function application.
- [Points 3]
The following code describes a function in SML.
fun g nil = true
| g (x::nil) = false
| 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.
- It does not define a function since it causes a match exception error.
- [Points 2]
What is the value computed for the following expression? 11
let val x = 5
in let val x = 3
in x + x
end
+ x
end;
- [Points 3]
What happens when SML is given the following code?
fun f 0 = 0
| f n = 1 + f(n - 1);
- Gives a type error.
- Defines a function which when applied to a non-negative
integer n, returns the value n.
- Defines a function that gives a runtime error when applied to 1.
- Defines a function which when applied to an integer, returns the
squares that integer.