This preview shows pages 1–2. Sign up to view the full content.
Suggested Homework #3
Suggested Homework #4 (for Quiz #4 on 10/29/06)
Problem 1:
Suppose that the following list of bindings was entered into the OCaml interpreter
in the sequence shown. For each binding, write down :
(a) If the expression is accepted, the value bound ("fun" for functions) and its type,
(b) If the expression is rejected due to a type error, "type error",
(c) If the expression is rejected due to an unbound variable, the name of the variable that is
not bound. Recall that if a type error occurs, then the variable binding does not happen. Check
your answers by entering this sequence into the interpreter.
 let foo (f,g) = fun x > (f x,g x);;
 let a = (foo (fun x > x*x, fun x > [x])) 4;;
 let b = (foo (fun x > ~x, fun x > 0::x)) (4,[4]);;
 let bar (f,a) = fun b > f (a,b);;
 let sum (a,b) = a+b;;
 let c = (bar (sum,1));;
 let d = c 2;;
 let f = (bar (bar,bar)) sum;;
 let g = f 4;;
 let h = g 4;;
 let i = h 4;;
 let j = i 4;;
Problem 2:
In each part below you are required to complete the
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '06
 Jhala

Click to edit the document details