Midterm2-Sol-Fall07

# Midterm2-Sol-Fall07 - 1 CS421 Fall 2007 Midterm 2 Tuesday...

This preview shows pages 1–4. Sign up to view the full content.

1 CS421 Fall 2007 Midterm 2 Tuesday, November 6, 2007 You have 75 minutes to complete this exam. This is a closed-book exam. . You are allowed one 3inch by 5 inch card of notes prepared by yourself. This card is not to be shared . All other materials, besides pens, pencils and erasers, are to be away. Do not share anything with other students. Do not talk to other students. Do not look at another student’s exam. Do not expose your exam to easy viewing by other students. Violation of any of these rules will count as cheating. If you believe there is an error, or an ambiguous question, you may seek clarification from myself or one of the TAs. You must use a whisper, or write your question out. Speaking out aloud is not allowed. Including this cover sheet and rules at the end, there are 12 pages to the exam. Please verify that you have all 12 pages. Please write your name and NetID in the spaces above, and also at the top of every page. Problem Possible Points Points Earned 1 15 2 18 3 15 4 12 5 10 6 20 7 10 PreTotal 100 Extra Credit 8 PostTotal 108 Name: NetID:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 CS 421 Midterm 2 Name:____________________________________ 1. (15 pts total) Using the rules described in class, and found at the back of this exam, give a full type derivation for the following type judgment: { } |- let rec f = fun x -> f (x – 1) in let y = ((f 3) > 0) in y : bool Solution: 11 12 {f:int->int, {f:int->int, 13 14 x:int} x:int} {f:int->int} {f:int->int} |- x:int |- 1:int |-f:int->int |-3:int 7 8 9 10 {f:int->int, x:int} {f:int->int, x:int} {f:int->int} {f:int->int} |- f:int->int (x-1):int |- (f 3): int |-0: int 4 5 6 {f:int->int, x:int} {f:int->int} {f:int->int, y:bool} |- f (x – 1) : int |- ((f 3) > 0) :bool y:bool 2 3 {f:int->int} |- fun x -> f (x – 1) : int->int {f:int->int} |- let y = ((f 3) > 0) in y : bool 1. { } |- let rec f = fun x -> f (x – 1) in let y = ((f 3) > 0) in y : bool 1: Let Rec Rule 2: Fun Rule 3: Let Rule 4,9: Application Rule 5: Relations Rule 6, 7, 11.13:Variable Rule 8: Primitive Operations 12. 14: Constant Rule
3 CS 421 Midterm 2 Name:____________________________________ 2. (18 points) Give a most general unifier for the following unification problem. Capital letters denote variables of unification and lower case letters denote constructors. Show all your work by listing the operation being performed at each step, and all the results of that operation. { f(A,B) = f(p(C,D),p(D,C)),

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.

{[ snackBarMessage ]}

### Page1 / 12

Midterm2-Sol-Fall07 - 1 CS421 Fall 2007 Midterm 2 Tuesday...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online