







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
The cs421 fall 2005 midterm exam for a computer science course. The exam covers various topics in ocaml programming, including function definitions, recursion, and type derivation. Students are required to solve multiple-choice and problem-solving questions within a given time limit and under strict exam conditions.
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Thursday, October 13, 2005
Problems Possible Points Points Earned 1 2 3 4 5 6 7 8 9 10
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________
(#5)__ |- (#6): (#7) (#8)__ |- (#9): (#10) (#11)__ |- (#12): (#13)
(#1)__ |- (fun x -> x):(#2)__ (#3)___ |- (f 7):(#4)____
_ { } |- (let rec f = fun x -> x in f 7) :int (#1) ________________________________________________________________ (#2) ________________________________________________________________ (#3) ________________________________________________________________ (#4) ________________________________________________________________ (#5) ________________________________________________________________ (#6) ________________________________________________________________ (#7) ________________________________________________________________ (#8) ________________________________________________________________ (#9) ________________________________________________________________ (#10) ________________________________________________________________ (#11) ________________________________________________________________ (#12) ________________________________________________________________ (#13) ________________________________________________________________
CS 421 Midterm Name:____________________________________
CS 421 Midterm Name:____________________________________ (7 cont) c. (6 pts) Reduce this term to αβ-normal form: (You may omit explicit mention or use of congruence closure)
CS 421 Midterm Name:______________________________
0 g g f f f f f f g g f f g g f
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