1. What is the output of the following in ML? Just the final output
val fred = true;
fred;
A. val fred = true: bool
B. val it = true: bool
C. val fred = true: boolean
D. val it = true: boolean
2. What is the result of the following:
let val x = 1 val y = 3 in x + y end;
A. val it = 4 : int
B. val it = 3 : int
C. val it = 1 : int
D. val it = 2 : int
3. What is the output of the following in ML?
2 < 3;
A. val it = true : boolean
B. val it = true : bool
C. val it = false : boolean
D. val it = false : bool
4. What is the result of the following in ML?
true andalso 1 div 0 = 0;
A. val it = true : bool
B. Throw exception because of divide by 0
C. val it = false : bool
D. Error because there is no operator named andalso
5. What is the type of the following result?
[1, 2, 3];
A int list list
B int * int * int
C list list
D int list
6. Write a function and call it Second.
The function is of type 'a list -> ‘a
this functions returns the Second element of a list.
Note: Its ok if your function does not behave well on lists with less than 2 elements
7. What is the output of the following in ML?
1 < 2 or 3 > 4;
A val it = true : bool
B val it = false : bool
C Error
D val it = true : boolean
8. What is the result of the following?
[ ];
A val it = false : bool
B vali it : = true : bool
C val it = [ ] : list
D val it = [ ] : ‘a list
9. Which of the following will produce a warning message?
A fun f 0 = “yes”;
B fun f _ = “yes”;
C fun f x = “yes”;
D none of the above
10. Consider the following function
fun merge (nil, ys) = ys
| merge (xs, nil) = xs
| merge (x :: xs, y :: ys) =
if (x < y) then x :: merge (xs, y :: ys)
else y :: merge(x :: xs, ys);
What is the result for the following statement:
merge ([1, 2, 3], [4, 5, 6]);
A val it = [1, 2, 3, 4, 5, 6] : list
B val it = [1, 2, 3, 4, 5, 6] : int list
C val it = [1, 4, 2, 5, 3, 6 ] : int list
D val it = [1, 3, 5, 2, 4, 6] : int list