We have provided below a list of suggested problems that you can use to prepare for the final exam. We strongly encourage you to solve these problems independently. We will release solutions to selected problems after the "open office hours" on Monday, December 13.
If you have any questions about the problems, feel free to post your questions/thoughts on the newsgroup. As opposed to regular homework problems, the solutions to these problems will not be graded. We thus encourage you to post and discuss solutions openly.
Check this page every now and then for updates.
Feel free to use the Mini-ML handouts that you were given in class when solving the problems below. We will provide you with handouts during the exam as well.
| (TUPLE_T lt1, TUPLE_T lt2) => if not(length lt1 = length lt2) then raise StaticTypeError err_str else let TUPLE_T (map (fn (t1, t2) => type_unification(t1, t2, err_str) (ListPair.zip(lt1, lt2))) end
((fn (n: int) => raise Fail "bad") 3) ^ "alpha"
Perform the changes changes needed to modify the interpreter to implement the two alternative semantics described above.
Modify the interpreter so that you implement the treatment of mini-ML exceptions in function applications as described above. Comment on the impacts of this change in semantics in terms of execution time, resource utilization, and other factors that you find relevant.
let val x = 3 in let fun f1(n: int): int->int = if x = 0 then (raise Fail "failed") else (fn (y:int) => y + n) in let fun f2(n: int): int = if x = 0 then f2(n) else x in (f1(3)) (f2(5)) end end end
Keeping in mind that all mini-ML programs must be written on one line, and that the code above has been edited for readability, state what the code will evaluate to for various values of x (P9) assuming the default treatment of exceptions in mini-ML, and (P10) assuming that the treatment of exceptions has been changed as described above.
Mini-ML> let val x = 3 in evaluate_default(false, if y then x else x + 5) endIn the case illustrated above the mini-ML should evaluate to 8.
The order of the problem is not significant, it merely reflects the order in which problems have been added to this list. Problems earlier in the list are not necessarily more/less important, or easier/harder than problems toward the end of the list.
let (* 1 *) fun f1 ... = ... f2 ... f3 ... (* 2 *) and f2 ... = ... f3 ... f1 ... (* 3 *) and f3 ... = ... f1 ... f2 ... (* 4 *) in ... endWe have skematically represented three mutually recursive functions. Show the environment diagram at points (1), (2), (3), and (4) above.
let val x: int = 7 val y: int = 9 in x + y endProvide an example in which at least one binding created in a let statement must be preserved (i.e. it can not be removed, or garbage collected) as soon as the evaluation of the respective let statement ends.
H(m,n) = a * H(m-1,n) + b*H(m-1,n-1) H(0,0)=1.0 H(m,n)=0 if mNote: This problem is hard; it was posted as a challenge on the newsgroup earlier this semester; Tibor provided a solution that you can look up there. - P26: State the type of the expressions below (a) ((((())))) (b) (((((1)))))
- P27: Consider the following type definition:
datatype values = Null | INT of int | REAL of realWhat is the value of the expression below:let fun f(v: values) = case v of NULL => 0 | INT i => i * i | REAL r => Real.floor (r * r) in REAL 2.5 endHint: This is a trick question.- P28: Consider the usual definition of streams below
datatype 'a stream = Null | Stream of 'a * (unit -> 'a stream)Write function concat which takes a stream of integer streams, and returns a stream of integers which is the concatenation of the streams from the function's arguments. For example,val s1 = Stream(1, fn () => Null) val s2 = (Null: int stream) val s3 = Stream(2, fn () => Stream(3, fn () => Null)) concat(Stream(s1, fn () => Stream(s2, fn () => Stream(s3, fn () => Null))))should return Stream(1, fn() => Stream(2, fn () => Stream(3, fn () => Null))). Keep in mind that streams can be infinite.- P29: Write a mini-ML program that can be used to establish whether the interpreter uses static or dynamic scoping. State the values that your program would return in both cases. Draw the environment diagram both for the static and the dynamic scoping case and use these diagrams to explain the reasoning behind your solution.
- P30: REPLACE strings ford, type, and marvin so that the expression below evalutes to (2004, 312):
let fun ford: type = marvin in (39 * 8, 167 * 12) end