cs173: Programming Languages

Similar documents
cs173: Programming Languages Final Exam

cs173: Programming Languages Midterm Exam

cs173: Programming Languages

Threads. {seqn {spawn EXPR 1 } {spawn EXPR 2 }} Runs EXPR 1 and EXPR 2 in any order, even interleaved with each other

CSE505, Fall 2012, Midterm Examination October 30, 2012

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

An Introduction to Functions

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

CPSC 311, 2010W1 Midterm Exam #2

Implementing Continuations

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Agenda. CS301 Session 11. Common type constructors. Things we could add to Impcore. Discussion: midterm exam - take-home or inclass?

Quick announcement. Midterm date is Wednesday Oct 24, 11-12pm.

Higher-Order Functions (Part I)

Harvard School of Engineering and Applied Sciences Computer Science 152

CS 314 Principles of Programming Languages

COSE212: Programming Languages. Lecture 0 Course Overview

Higher-Order Functions

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Lexical Addresses. let x = 1 y = 2 in let f = proc (x) +(x, y) in (f x) let _ = 1 _ = 2 in let _ = proc (_) +(<0,0>, <1,1>) in (<0,0> <1,0>)

Recap: Functions as first-class values

CSE 505, Fall 2008, Final Examination 11 December Please do not turn the page until everyone is ready.

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

CS4215 Programming Language Implementation. Martin Henz

CSE 505, Fall 2008, Final Examination 11 December Please do not turn the page until everyone is ready.

Typed Recursion {with {mk-rec : (((num -> num) -> (num -> num)) -> (num -> num)) {fun {body : ((num -> num) -> (num -> num))} {{fun {fx :

3.7 Denotational Semantics

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

Implementing Recursion

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Comp 311: Sample Midterm Examination

Introduction to OCaml

A Functional Evaluation Model

UNIVERSITY OF CALIFORNIA

CPSC 311, 2011W1 Midterm Exam #2 2011/11/09

CS611 Lecture 33 Equirecursive types & Recursive domain equations November 19, 2001

cmpt 440/821 Advanced Topics in Programming Languages

CS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th

CSE 240 Introduction to Computer Architecture

Types and Programming Languages. Lecture 5. Extensions of simple types

Cost of Substitution

CSE 341: Programming Languages

Class Note #02. [Overall Information] [During the Lecture]

Programming Languages

Organization of Programming Languages CS3200/5200N. Lecture 11

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Types, Expressions, and States

Understanding Recursion

Variables. Substitution

Lecture 3: Recursion; Structural Induction

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

1 Delimited continuations in Haskell

Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)

CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009

CS422 - Programming Language Design

The story so far. Elements of Programming Languages. Pairs in various languages. Pairs

CSE 505, Fall 2008, Midterm Examination 29 October Please do not turn the page until everyone is ready.

Introduction to Scheme

Mutable References. Chapter 1

Type Checking and Type Inference

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

CPSC W1 University of British Columbia

Types and evaluation

Programming Languages Assignment #7

Overview. A normal-order language. Strictness. Recursion. Infinite data structures. Direct denotational semantics. Transition semantics

CS 11 Haskell track: lecture 1

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Programming Languages and Compilers (CS 421)

Last class. CS Principles of Programming Languages. Introduction. Outline

Lecture 13 CIS 341: COMPILERS

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG

Type Declarations. [... <id> τ... ] <id> : τ. Γ <num> : number. Γ true : boolean. Γ false : boolean. Γ e 1 : number.

Welcome to CS 115 (Winter 2018)

Introduction to Programming, Aug-Dec 2006

Agenda. CS301 Session 9. Abstract syntax: top level. Abstract syntax: expressions. The uscheme interpreter. Approaches to solving the homework problem

Midterm 1. CMSC 430 Introduction to Compilers Spring Instructions Total 100. Name: March 14, 2012

Lecture #23: Conversion and Type Inference

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler.

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

> module Lambda where > import Data.List -- I need some standard list functions

Part III. Chapter 15: Subtyping

Structure and Interpretation of Computer Programs

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

Where is ML type inference headed?

CS558 Programming Languages

Programming Languages Lecture 15: Recursive Types & Subtyping

CS 152: Programming Languages

Programming Language Concepts, cs2104 Lecture 01 ( )

Survey of Programming Languages Dr. R. M. Siegfried 407 Science (516) (not for homework submission)

MIDTERM EXAMINATION - CS130 - Spring 2003

CSE341 Spring 2017, Final Examination June 8, 2017

Dynamic Types , Spring March 21, 2017

Variables and Bindings

CSE341: Programming Languages Lecture 26 Course Victory Lap. Dan Grossman Spring 2016

CS115 - Module 10 - General Trees

Transcription:

The questions on this exam are worth 100 points. Exam rules: cs173: Programming Languages Midterm Exam Fall 2000 Your responses to this exam are due before the start of class on 2000-11-08. If you believe a question is underspecified, make a reasonable assumption, and document your claim and your work-around. The exam is open book with respect to the course text (Krishnamurthi and Felleisen) and course lecture notes (Tucker and Krishnamurthi, with a guest appearance by Blaheta). You may cite these by lecture date. You may not refer to any other sources related to the course between the time you start and finish the exam. You have three hours and 15 minutes to take this exam. Time begins when you start reading the exam questions. The first three hours must be a single, contiguous block. After you have completed this period, you must close your responses. At some later point, at your discretion (and before the responses are due), you may open your responses for one 15 minute period to edit or append to them. All code responses must use the dialect of Scheme employed in this course. You may not use side-effects or continuations unless expressly permitted to do so in the problem statement. Staple your solutions together. Put your name or initials on every page. Solutions may be hand-written, but the burden of legibility rests on you. You may not evaluate any of programs related to this exam on a computer. You must neither give assistance to any other course participant, nor receive assistance from anyone other than the course staff, on material under examination. Brown University has an Academic Code that governs this exam and all our other transactions. I expect you, as students and scholars, to abide by it faithfully and fully. 1

Problem 1 [15 points] Continuing our obsession with the Greek alphabet, let us consider the ι-calculus (IC). The IC is an extension to the (eager) λ-calculus. It extends the language with a new keyword, iota. iota is always bound to the time elapsed since the program began execution (as in, an iota of time ), so the value of iota tells the programmer how long the program has been running. Time is discrete. It begins at 0, and increases by 1 at each function application. The IC can be used to profile program execution or to implement pre-emptive multi-tasking. We ve extended the abstract syntax for you. Extend or modify the interpreter to implement the ι-calculus. You may use mutation in your interpreter. (define-datatype IC IC? [nume (n number?)] [vare (v symbol?)] [adde (lhs IC?) (rhs IC?)] [fune (param symbol? )(body IC?)] [appe (func IC?) (arg IC?)] [iotae]) ;; new syntax clause ;; assume the implementation of D-Sub (define (interp a d) (cases IC a [nume (n) n] [vare (v) (get-sub v d)] [adde (le re) (+(interp le d) (interp re d))] [fune (param body) (λ (argval) (interp body (new-sub param argval d)))] [appe (fe ae) ((interp fe d) (interp ae d))])) 2

Problem 2 [15 points] Your slightly daffy boss, having once taken a survey of programming languages course, fancies himself as a language designer. It s your lot in life to satisfy his megalomania. Fascinated by tinkering with features, he asks you to extend your in-house implementation with the following construct, i-letrec (short for irreflexive letrec ), which is syntactically similar to but semantically a cross between let and letrec. Syntax: Binding: The expression extends its inherited environment as follows: (i-letrec ([var expr]...) expr) (i-letrec ([var 1 expr 1 ]... [var n expr n ]) body) {var 1,..., var n } {var k } are bound in expr k (In contrast, letrec binds all the var i in each expr k,andlet binds none of them) {var 1,..., var n } are bound in body (All of these variables are bound in body in letrec and let, too) N.B.: denotes set difference. Semantics: Problem: i-letrec evaluates all the expr i in parallel, assigns each value to the corresponding var i,then evaluates and returns the value of body.anyuseofavar i in an expr j must be in the body of a function. (This is also expected of letrec terms.) Thus, (i-letrec ([x 3] [y x]) y) is illegal, but (i-letrec ([x 3] [y (λ () x )]) (y)) is not. Write three side-effect-free Scheme expressions that are syntactically identical in all respects except where one uses let, another uses letrec, and the third i-letrec. No two expressions may evaluate to the same result. None of them should produce an error. At most one of the expressions may fail to terminate. Specify the resulting value for each expression. The solution expression may use let and letrec. (You may of course write the expression just once, and indicate the locus of the change.) 3

Problem 3 [25 points] Consider the language L ::= N where N {1, 2, 3,... } (L + L) id (fun (id) L) (L (L)) (set id L) Provide an operational semantics for this language using the style of semantics in the lecture on 2000-10-06. The semantics of set is the same as that of Scheme s set!. This is the same exercise as homework Program 3 because there is no mutation operation in mathematics, either. The difference lies not in the solution but in how you express it: you must use mathematics, not Scheme code. You may use standard mathematical values such as sets, tuples, and so forth. 4

Problem 4 [25 points] Consider the language You are given the following rules: L ::= N where N {1, 2, 3,... } x (fun (x ) L) (L L) Γ(x) =τ Γ x : τ Γ[x : τ ] L : τ Γ (fun (x ) L) :(τ τ) Γ N : num Γ L f :(τ τ) Γ L a : τ Γ (L f L a ):τ The rule for fun is magical : it uses variables to guess types, expecting the user to eventually resolve the guesses. Provide a type for the term (((fun (x ) x )(fun (x ) x )) 3) by generating and solving one or more constraints. The final type must not contain any variables: it must be in terms of num and only. Suggestion: Turn the page by 90 before you start writing. 5

Problem 5 [20 points] Consider the following features we have studied in class: (1) parametric polymorphism (2) polymorphic datatypes Many languages that offer one of these features offer both, e.g., ML and Haskell. Does it make sense to include them individually? Consider a language with (1) but not (2). Characterize the programs you can write that exploit (1). [10 points] Consider a language with (2) but not (1). What kinds of programs can you write that exploit (2)? [10 points] 6