








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Progrmg Languages & Compilers; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2006;
Typology: Exams
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Tuesday, October 10, 2006
Problems Possible Points Points Earned 1 2 3 4 5 6 7 8 Total 10
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________
Please complete the derivation by giving the results that go in the lettered blanks. Put your answers next to the corresponding letters below the type derivation outline. You should answer using concrete types; there are no type variables required for this problem.
(#17) |- (#18): (#19)_ (#20) |- (#21): (#22)_
(#14)_ |- (#15): (#16)
(#5)_ |- (#6): (#7) (#8)_ |- (#9): (#10) (#11)_ |- (#12)_ (#13)_
(#1)_ |- (fun x -> fun y -> x+y):(#2)_ (#3)_ |- (f 3 ):(#4)_
_ { } |- (let rec f = fun x -> fun y-> x + y in f 3) :int -> int (#1) ____{f : int -> int -> int }__________________________________________ (#2) _____: int -> int -> int____________________________________________ (#3) ____{f : int -> int -> int }___________________________________________ (#4) _____: int -> int __________________________________________________ (#5) ____{x:int; f : int -> int -> int }_____________________________________ (#6) ____ fun y -> x+y_________________________________________________ (#7) _____: int -> int __________________________________________________ (#8) ____{f : int -> int -> int }____________________________________________ (#9) ______f__________________________________________________________ (#10) _____:int -> int -> int ____________________________________________ (#11) ____{f : int -> int -> int }__________________________________________
CS 421 Midterm Name:____________________________________ 5 (cont.) (20 pts total) Below I have given you an outline for the type derivation of the following expression:
Please complete the derivation by giving the results that go in the lettered blanks. Put your answers next to the corresponding letters below the type derivation outline. You should answer using concrete types; there are no type variables required for this problem.
(#17) |- (#18): (#19)_ (#20) |- (#21): (#22)_
(#14)_ |- (#15): (#16)
(#5)_ |- (#6): (#7) (#8)_ |- (#9): (#10) (#11)_ |- (#12)_ (#13)_
(#1)_ |- (fun x -> fun y -> x+y):(#2)_ (#3)_ |- (f 3 ):(#4)_
_ { } |- (let rec f = fun x -> fun y-> x + y in f 3) :int -> int (#12) ______ 3 _________________________________________________________ (#13) ______:int_______________________________________________________ (#14) ____{y:int, x:int; f : int -> int -> int }________________________________ (#15) ______ x+y ______________________________________________________ (#16) ______:int ______________________________________________________ (#17) ______ {y:int, x:int; f : int -> int -> int }______________________________ (#18) _______x________________________________________________________ (#19) _______:int _____________________________________________________ (#20) ______ {y:int, x:int; f : int -> int -> int }______________________________ (#21) _______y________________________________________________________ (#22) ______:int _____________________________________________________
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________ 7 (cont) (12 points) Given the following lambda expression: (λ x. λ y. x y x) ((λ s. λ t. s t) (λ z. z)) In each of the evaluations below, show each step, and label it with the type of reduction or conversion performed. (You may omit explicit mention or use of congruence closure) c. (6 pts) Reduce this term to αβ-normal form: Solution: (λ x. λ y. x y x) ((λ s. λ t. s t) (λ z. z))
CS 421 Midterm Name:______________________________
CS 421 Midterm Name:______________________________ Rules for type derivations: Constants:
Γ|- n : int (assuming n is an integer constant)
Γ|- true : bool Γ|- false : bool Variables:
Γ |- x : σ if Γ(x) = σ Primitive operators ( ⊕ ∈ { +, -, *, …}): Γ |- e 1 : int Γ |- e 2 : int Γ |- e 1 ⊕ e 2 : int Relations ( (^) ˜ ∈ { < , > , =, <=, >= }): Γ |- e 1 : int Γ |- e 2 : int Γ |- e 1 ˜ e 2 :bool Connectives : Γ |- e 1 : bool Γ |- e 2 : bool Γ |- e 1 : bool Γ |- e 2 : bool Γ |- e 1 && e 2 : bool Γ |- e 1 || e 2 : bool If_then_else rule: Γ |- e 1 : bool Γ |- e 2 : τ Γ |- e 3 : τ Γ |- (if e 1 then e 2 else e 3 ) : τ Application rule: fun rule: Γ |- e 1 : τ 1 → τ 2 Γ |- e 2 : τ 1 [x : τ 1 ] + Γ |- e : τ 2 Γ |- (e 1 e 2 ) : τ 2 Γ |- fun x -> e : τ 1 → τ 2 let rule: let rec rule: Γ |- e 1 : τ 1 [x : τ 1 ] + Γ |- e 2 : τ 2 [x: τ 1 ] + Γ |- e 1 :τ 1 [x: τ 1 ] + Γ |- e 2 :τ 2 Γ |- (let x = e 1 in e 2 ) : τ 2 Γ |- (let rec x = e 1 in e 2 ) : τ 2