- [Pts 2]
Consider the definition
fun f [] = 0
| f (x::L) = x + (f L) - 1;
What is the result of f [0,1,2]; ? (only one answer, please)
- error
- 0
- 2
- ~1 (remember that "~" in ML is the unary minus sign)
- [Pts 2]
What is the effect at the end of the following sequence of declarations? (only one answer, please)
val x = 1;
val y = 2;
val (x,y) = (y,x);
- The truth value false, because 2 is not equal to 1
- Error, because the keyword "val" expects a variable afterwards
- x and y are both assosiated to the value 2
- x is associated to the value 2 and y is associated to the value 1
- [Pts 2]
What is the result of the expression hd [[1],[2],[3]]; (only one answer, please. Remember that hd represents the function "head of a list".)
- 1
- [1]
- error
- the pointer to the first element of the list (i.e. to the element which contains [1])
- [Pts 4]
Consider the following definition:
fun app [] L = L
| app (x::K) L = x::(app K L);
For each of the following expressions, say what is the result, or say whether it's an error.
- app ["Mario"] []; ["Mario"]
- app ["Mario"] ["Luigi"]; ["Mario","Luigi"]
- app ["Mario"] [1]; error
- app ["Mario",["Luigi"]] ["Piero"]; error