Computer Science 164 - Fall 1998 - Aiken - Midterm 2

Computer Science 164 - Fall 1998 - Aiken - Midterm 2 - CS...

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

CS 164, Midterm #2, Fall 1998 CS 164, Fall 1999 Midterm #2 Professor Aiken Problem #1: Parametric Polymorphism Consider the functional language grammar used in class: Program -> Definition; Definitions | Definition -> Id(Id) = Expr Expr -> Id | (Expr Expr) | (fun Id expr) | i | (Expr + Expr) | [Expr, Expr] | (first Expr) | (second Expr) In this language, the construct (Expr 1 Expr 2 ) is a function application where Expr 1 is the function and Expr 2 is the argument. The expression (fun Id Expr) is an anonymous function with argument Id and body Expr (the equivalent of lambda in Scheme). A i is an integer constant, [Expr, Expr] creates a pair of the values of the two expressions, and first and second are selectors for the first and second for the first and second components of pairs, respectively. For each of the following types, give an expression (from the language above) for which this is the principal type. a. int -> int b. (( α × β ) × γ ) -> ( γ × ( β × α )) c. α -> (( α -> β ) -> β ) Problem #2: Code Generation file:///C|/Documents%20and%20Settings/Jason%20Raft. ..0-%20Fall%201998%20-%20Aiken%20-%20Midterm%202.htm (1 of 4)1/27/2007 6:38:05 PM

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

View Full Document
CS 164, Midterm #2, Fall 1998 Consider a for construct for i = e 1 to e 2 by e 3 do e 4 The subexpressions are integer-valued. A for is evaluated according to the following rules. The first three subexpressions are evaluated once at the start of the loop in the order
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2009 for the course CS 164 taught by Professor Staff during the Spring '08 term at University of California, Berkeley.

Page1 / 4

Computer Science 164 - Fall 1998 - Aiken - Midterm 2 - CS...

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

View Full Document
Ask a homework question - tutors are online