Computer Science 164 - Fall 1999 - Rowe - Midterm 2

Computer Science 164 - Fall 1999 - Rowe - Midterm 2 - CS...

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

View Full Document Right Arrow Icon
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. ..20-%20Fall%201999%20-%20Rowe%20-%20Midterm%202.htm (1 of 4)1/27/2007 6:38:04 PM
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Computer Science 164 - Fall 1999 - Rowe - Midterm 2 - CS...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online