上海交通大学试卷 ( A 卷 ) ( 2015 至 2016 学年第 2 学期 )
|
|
- Violet Ford
- 6 years ago
- Views:
Transcription
1 上海交通大学试卷 ( A 卷 ) ( 2015 至 2016 学年第 2 学期 ) 班级号 (class) 学号 (id) 姓名 (name) 课程名称 程序语言理论 Theory of Programming Languages 成绩 (score) 1. (14 points) (a) Please give the value of a0, a1 after running the following Ocaml program: let f0 x = x + x + x let x0 = ref 3 let a0 = f0 (x0:=!x0+1;!x0) let f1 x = x() + x() + x() let x1 = ref 3 let a1 = f1 (fun () -> (x1:=!x1+1;!x1)) (b) Please argue the differences between call-by-value and call-by-name strategies. (c) Can you give one piece of Ocaml code that diverges(does not terminate) by using call-by-value strategy, but terminates by using call-by-name strategy? (d) Assume we have the following evaluation rules for untyped λ-calculus. Please select the rules for call-by-value strategy; and select those for call-by-name strategy. β-red1 (λx.t1 ) t 2 [x t 2 ] t 1 β-red2 (λx.t) v [x v] t App1 t 1 t 1 t 1 t 2 t 1 t 2 App2 t 2 t 2 t 1 t 2 t 1 t 2 App3 t 2 t 2 v 1 t 2 v 1 t 2 (a) a0 = 12; a1 = 15 (b) Call-by-name strategy always carries out the leftmost and outermost β-redex; Call-by-value strategy further requires that β-reduction happens after the argument part has been evaluated to a value; (c) let f x = 0 let rec g x = g x let a = f (g 0) (d) Call-by-name: β-red1, App1 Call-by-value: β-red2, App1, App3 1
2 我承诺, 我将严格遵守考试纪律 承诺人 : 题号得分批阅人 ( 流水阅卷教师签名处 ) 总分 2. (12 points) 2. (12 ) Given This problem the subtyping considers rules this in Ruby Fig. class: 1 on page 9. class A (a) How many attr_accessor different supertypes :x does {a : Top, b : Top} have? (b) Can you find m1 an infinite descending chain in the subtype relation? i.e., an infinite sequence of types = 4 0, S 1,... such that for any i, S i+1 <: S i. (c) What about end an infinite ascending chain? (d) If we add a new m2 typing rule m1 > 4 please figure end out the relation between Nat <: Float m3 = 4 1 = {a : Nat Float, b : {}} > 4 T end 2 = {a : Float Nat, b : {c : Nat}} If T 1 an T 2 has m4 subtyping relation, give the derivation tree; If not, explain the reason briefly. self.x = > 4 end (a) {a:top,b:top},{b:top,a:top},{a:top},{b:top},{}, Top end (b) S 0 ={}, S 1 ={a:top}, S 2 ={a:top,b:top}, etc. (c) T 0 = S 0 Top, T 1 = S 1 Top, T 2 = S 2 Top, etc. 1) (4 ) Is it possible to ine a class B such that evaluating B.new.m2 causes the method m2 (d) T 2 <: T ined 1. The derivation tree is omitted. in class A (not an override of m2) to return true? If so, ine class B as such, else explain why it is not possible. 2) (4 ) Is it possible to ine a class B such that evaluating B.new.m3 causes the method m3 ined in class A (not an override of m3) to return true? If so, ine class B as such, else explain why it is not possible. 3) (4 ) Is it possible to ine a class B such that evaluating B.new.m4 causes the method 2 m4 ined in class A (not an override of m4) to return true? If so, ine class B as such, else explain why it is not possible.
3 A Name:, Id: 3. (14 points) Recursive type is very powerful, it can make infinite data. This problem consider a typed λ-calculus with variant types, pairs, recursive types, fix, Unit, and Nat. Please refer to Fig. 2 on page 9 for syntax of variants. (a) Define a type NatList for a list of natural numbers where each list is either a nil of unit or cons of a pair of type Nat NatList. (b) Give a value of type NatList that has two elements 0 and succ0, and 0 is the head of this list. (c) Define a function hd of type NatList Nat that returns the head of a list. Return 0 if the given list is nil. (d) Define a function sum of type NatList Nat that returns the summation of all the numbers in a list. You can use (plus m n) directly for m + n. (a) NatList = µx. < nil : unit, cons : Nat X >. (b) < cons = (succ0, < cons = (0, < nil = unit > as NatList) > as NatList) > as NatList (c) hd = λl : NatList.case l of < nil = x > 0 < cons = p > p.1 (d) sum = fix λm : Natlist Nat.λl : NatList.case l of < nil = x > 0 < cons = p > plus p.1 (m p.2) 3
4 4. (10 points) Suppose a generating function F on the universe {a, b, c, d} is ined by the following inference rules: c d b c b d c a A set S is F -closed if F (S) S; it is F -consistent if S F (S); it is a fixed point if S = F (S). (a) List all the F -closed sets. (b) List all the F -consistent sets. (c) What is the least fixed point of F? What is the greatest fixed point of F? (a) F -closed: {b}, {a, b}, {a, b, c, d} (b) F -consistent sets:, {b}, {c, d}, {b, c, d}, {a, b, c, d} (c) µ F = {b}, ν F = {a, b, c, d}. 4
5 A Name:, Id: 5. (12 points) This problem uses System F extended with addition. Please refer to Fig. 3 on page 10 for initions of System F. (a) Give the appropriate System F typing rule(s) and evaluation rule(s) for addition expressions of the form t 1 + t 2. (This should be easy.) (b) Consider a typing context Γ = x : X.X X: i. What does T need to be for the program fragment x [T] (λy : Nat.y + 7) 11 to typecheck? ii. Given your choice for T, what type does x [T] (λy : Nat.y + 7) have? Give a typing derivation for Γ x [T] (λy : Nat.y + 7). (c) Given your choice for T. If v is an arbitrary value of type X.X X, then what might v [T] (λy : Nat.y + 7) 11 evaluate to? (d) If v is an arbitrary value of type (Nat Nat) Nat Nat then what might v (λy : Nat.y + 7) 11 evaluate to? (a) E-Add-L t 1 t 1 t 1 + t 2 t 1 + t 2 E-Add-R t 2 t 2 v 1 + t 2 v 1 + t 2 T-Add Γ t 1 : Nat, Γ t 2 : Nat Γ t 1 + t 2 : Nat (b) i. (Nat Nat) ii. Nat Nat. The derivation tree omitted. (c) It will always evaluate to 18 (or you can write 11+7) due to parametricity. In System F, any value of type X.X X is totally equivalent to the identity function. You can not have any computations on a value of X. (d) It could produce any value whatsoever. 5
6 6. (12 points) Assume we have a typed programming language formally ined by a small-step operational semantics and a typing judgment. Assume the Preservation and Progress Theorems hold for this language. Preservation: If t : T and t t, then t : T. Progress: If t : T for some T. Then either t is a value or else there is some t with t t. Consider each question below separately and explain your answers briefly. (a) Suppose we change the operational semantics by adding a new inference rule. i. Is it possible that Preservation does not hold any more? ii. Is it possible that Progress does not hold any more? (b) Suppose we change the type system by adding a new typing rule. i. Is it possible that Preservation does not hold any more? ii. Is it possible that Progress does not hold any more? (a) (b) i. Yes, the new rule might produce an ill-typed term. ii. No, more operational rules cannot make it harder to step. i. Yes, the new rule might let some term type-check that can take a step to produce a term that doesn t type-check. As an example, suppose we have a rule give (3+4)+() type Nat. It can step to 7+(), which does not type-check. ii. Yes, the new rules could allow a stuck term to type-check. For example, have a rule that gives 3 + () type Nat. 6
7 A Name:, Id: 7. (10 points) This problem considers to translate a λ-term to the corresponding de Bruijn term. Here are some initions for your reference. A naming context Γ = x n, x n 1,, x 1, x 0 assigns to each x i the de Bruijn index i. The d-place shift of a term t about cutoff c, written d c (t) is ined as d c (k) = { k if k < c k + d if k c d c (λ.t 1 ) = λ. d c+1 (t 1 ) d c (t 1 t 2 ) = d c (t 1 ) d c (t 2 ) The substitution of a term s for variable number j in a term t, written [j s]t, is ined as follows: { s if k = j [j s]k = k otherwise [j s](λ.t 1 ) = λ.[j s]t 1 [j s](t 1 t 2 ) = [j s]t 1 [j s]t 2 The β-reduction rule on de Bruijn terms is: (λ.t 1 ) t 2 1 [0 1 t 2 ]t 1 (a) Let Γ = wa, give the nameless representation of (λb.w (λa.b a)) (λb.b a). (b) Show the computation (β-reduction) of this de Bruijn term step by step. (a) Nameless representation: (λ.2 (λ.1 0)) (λ.0 1) (b) (λ.2 (λ.1 0)) (λ.0 1) 1 [0 1 (λ.0 1)](2 (λ.1 0)) = 1 [0 (λ.0 2)](2 (λ.1 0)) = 1 (2 [0 (λ.0 2)](λ.1 0))) = 1 (2 λ.[1 1 (λ.0 2)](1 0))) = 1 (2 λ.[1 (λ.0 3)](1 0))) = 1 (2 λ.((λ.0 3) 0)) = (1 λ.((λ.0 2) 0)) 7
8 8. (16 points) This problem consider a simple programming language on booleans. Syntax: t::= true false if t then t else t diverg v::= true false Evaluation: E-IfTrue if true then t2 else t 3 t 2 E-IfFalse if false then t2 else t 3 t 3 E-If t 1 t 1 if t 1 then t 2 else t 3 if t 1 then t 2 else t 3 E-Diverg diverg diverg Below is one possible encoding from this small language to untyped call-by-value λ- calculus. true 1 false 1 if t_1 then t_2 else t_3 1 diverg 1 = λx.λy.x (1) = λx.λy.y (2) = t 1 1 t 2 1 t 3 1 (3) = (λx.xx)(λx.xx) (4) An encoding is termination preserving if for any term t, t terminates if and only if t terminates. (a) Give a counter example to show that the above encoding 1 is NOT termination preserving; (b) Give a termination preserving encoding 2 from this small language to untyped call-by-value λ-calculus, and prove it. (c) If we want to keep the encoding 1, please modify the evaluation rules for this small language to make 1 termination preserving, and prove it. (a) The term t = if false then diverg else false terminates. However the encoding t 1 = (λx.λy.y)(ω)(λx.λy.y) will diverge under call-by-value strategy. (b) We can solve this problem by thunking E2 and E3. Here is one possible solution: Let I = λx.x ture 2 false 2 if t_1 then t_2 else t_3 2 diverg 2 = λx.λy.xi = λx.λy.yi = t 1 2 (λx. t 2 2 ) (λx. t 3 2 ) = (λx.xx)(λx.xx) 8
9 (c) We keep rules E-IfTrue, E-IfFalse and Diverg, and change rule E-If to the following three rules. t 1 t 1 E-If-1 if t 1 then t 2 else t 3 if t 1 then t 2 else t 3 E-If-2 t 2 t 2 if v 1 then t 2 else t 3 if v 1 then t 2 else t 3. t 3 t 3 E-If-1 if v 1 then v 2 else t 3 if v 1 then v 2 else t 3 Both proofs can be carried out by structural induction on terms. 9
10 A References 16.1 Algorithmic Subtyping 211 Figure 1: Subtype relation with records {} <: Extends 15-1 and 15-3 S <: S S<:U U<:T S<:T S <: Top (S-Refl) (S-Trans) (S-Top) T 1 <:S 1 S 2 <:T 2 S 1 S 2 <:T 1 T 2 {l i i 1..n } {k j j 1..m } k j =l i impliess j <:T i {k j :S j j 1..m }<:{l i :T i i 1..n } (S-Arrow) (S-Rcd) 136 Figure 16-1: Subtype relation with records (compact version) 11 Simple Extensions Figure 2: Variants <> Extendsλ (9-1) derivations for records involving combinations of depth, width, and permutation subtyping. Before we can drop S-Trans, we must first add a rule that New syntactic forms bundles depth, width, and permutation subtyping t 0 t into 0 one: t ::=... terms: (E-Case) i 1..n i 1..n j 1..m case t {l i } {k j } k j =l i impliess 0 of <l i =x <l=t> as T tagging j <:T i > t i i case t (S-Rcd) i 1..n j 1..m i 1..n 0 case tof <l i =x i > t i {k j :S case j }<:{l i :T i } of<l i 1..n i=x i > t i t i t i T ::= Lemma: If S <: T is derivable types: from the subtyping rules including S-RcdDepth, <l i =t i > as T <l i =t (E-Variant) i 1..n i > as T <l i :T i S-Rcd-Width, > type and of S-Rcd-Perm variants (but not S-Rcd), then it can also be derived using S-Rcd (and not S-RcdDepth, New typing S-Rcd-Width, rules or S-Rcd-Perm), Γand t:t vice New evaluation rules versa. t t Γ t j :T j i 1..n i 1..n i 1..n case (<l j =v j > ast) Proof: of <l Straightforward i =x i > t i induction Γ <l on derivations. j =t j >as <l i :T i >:<l i :T i > [x j v j ]t j (T-Variant) Lemma justifies eliminating rules S-RcdDepth, S-Rcd-Width, and (E-CaseVariant) i 1..n S-Rcd-Perm in favor of S-Rcd. Figure 16-1 Γ t summarizes 0 :<l i :T i the> resulting system. Next, we show that, in the systemfor of eachi Figure 16-1, Γ,x i the :T i reflexivity t i :T and transitivity rules are inessential. Γ case t 0 of <l i =x i > t i (T-Case) i 1..n :T Lemma: Figure 11-11: Variants 1. S<:S can be derived for every type S without using S-Refl. 2. If S<:T is derivable, then it can be derived without using S-Trans Variants Proof: Exercise [Recommended, ]. Binary sums generalize to labeled variants just as products generalize to labeled records. [ ]: IfInstead we addoft the 1 type +T 2, we Bool, write<l how do 1 :Tthese 1,l 2 :T properties 2 >, wherel change? 1 andl 2 are Exercise field labels. Instead of inl tas T 1 +T 2, we write <l 1 =t>as <l 1 :T 1,l 2 :T 2 >. This Andbrings insteadusof tolabeling the inition the branches of the algorithmic of the casesubtype with inl relation. and inr, we use the same labels as the corresponding sum type. With these generalizations, Definition: The algorithmic subtyping relation is the least relation on types thegetaddr example from the previous section becomes: closed under the rules in Figure Addr = <physical:physicaladdr, virtual:virtualaddr>; a = <physical=pa> as Addr; a : Addr 10 getname = λa:addr. case a of <physical=x> x.firstlast <virtual=y> y.name;
11 23.3 System F 343 Figure 3: System F Based onλ (9-1) Syntax t ::= x λx:t.t t t λx.t t [T] terms: variable abstraction application type abstraction type application Evaluation t t t 1 t 1 t 1 t 2 t 1 t 2 t 2 t 2 v 1 t 2 v 1 t 2 (E-App1) (E-App2) (λx:t 11.t 12 ) v 2 [x v 2 ]t 12 (E-AppAbs) v ::= λx:t.t λx.t values: abstraction value type abstraction value t 1 t 1 t 1 [T 2 ] t 1 [T 2] (E-TApp) T ::= X T T X.T types: type variable type of functions universal type (λx.t 12 )[T 2 ] [X T 2 ]t 12 (E-TappTabs) Typing x:t Γ Γ x:t Γ t:t (T-Var) Γ ::= Γ,x:T Γ,X contexts: empty context term variable binding type variable binding Γ,x:T 1 t 2 :T 2 Γ λx:t 1.t 2 :T 1 T 2 Γ t 1 :T 11 T 12 Γ t 2 :T 11 Γ t 1 t 2 :T 12 (T-Abs) (T-App) Γ,X t 2 :T 2 Γ λx.t 2 : X.T 2 (T-TAbs) Γ t 1 : X.T 12 Γ t 1 [T 2 ]:[X T 2 ]T 12 (T-TApp) Figure 23-1: Polymorphic lambda-calculus (System F) is to keep track of scopes and make sure that the same type variable is not added twice to a context. In later chapters, we will annotate type variables with information of various kinds, such as bounds (Chapter 26) and kinds (Chapter 29). Figure 23-1 shows the complete inition of the polymorphic lambdacalculus, with differences fromλ highlighted. As usual, this summary de- 11 fines just the pure calculus, omitting other type constructors such as records,
12 12
上海交通大学试卷 ( A 卷 ) ( 2015 至 2016 学年第 2 学期 )
上海交通大学试卷 ( A 卷 ) ( 2015 至 2016 学年第 2 学期 ) 班级号 (class) 学号 (id) 姓名 (name) 课程名称 程序语言理论 Theory of Programming Languages 成绩 (score) 1. (14 points) (a) Please give the value of a0, a1 after running the following
More informationCMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008
CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008 Contents 1 Solution to the Exercise 1 1.1 Semantics for lambda calculus.......................
More informationCIS 500 Software Foundations Midterm I
CIS 500 Software Foundations Midterm I October 11, 2006 Name: Student ID: Email: Status: Section: registered for the course not registered: sitting in to improve a previous grade not registered: just taking
More informationFormal Systems and their Applications
Formal Systems and their Applications Dave Clarke (Dave.Clarke@cs.kuleuven.be) Acknowledgment: these slides are based in part on slides from Benjamin Pierce and Frank Piessens 1 Course Overview Introduction
More informationFall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.
Programming Languages Fall 2013 Midterm Exam 10/22/13 Time Limit: 100 Minutes Name (Print): Graduate Center I.D. This is a closed-book, closed-notes exam. Various definitions are provided in the exam.
More informationProgramming Languages Fall 2014
Programming Languages Fall 2014 Lecture 7: Simple Types and Simply-Typed Lambda Calculus Prof. Liang Huang huang@qc.cs.cuny.edu 1 Types stuck terms? how to fix it? 2 Plan First I For today, we ll go back
More informationCostly software bugs that could have been averted with type checking
Type Checking Class Notes from Lectures 6 and 7 Lahav Yeffet and Ori Folger The material in these lectures is based on the textbook Types and Programming Languages by Benjamin Pierce. Here is a list of
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationλ calculus is inconsistent
Content Rough timeline COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Toby Murray λ Intro & motivation, getting started [1] Foundations & Principles
More informationLambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,
Lambda Calculus Type Systems, Lectures 3 Jevgeni Kabanov Tartu, 13.02.2006 PREVIOUSLY ON TYPE SYSTEMS Arithmetical expressions and Booleans Evaluation semantics Normal forms & Values Getting stuck Safety
More informationPart III. Chapter 15: Subtyping
Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule
More informationCSE-321 Programming Languages 2011 Final
Name: Hemos ID: CSE-321 Programming Languages 2011 Final Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 15 15 10 17 18 25 100 There are six problems on 18 pages in this exam, including one extracredit
More informationSubsumption. Principle of safe substitution
Recap on Subtyping Subsumption Some types are better than others, in the sense that a value of one can always safely be used where a value of the other is expected. Which can be formalized as by introducing:
More informationCSE-321 Programming Languages 2010 Final
Name: Hemos ID: CSE-321 Programming Languages 2010 Final Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 18 28 16 12 36 40 150 There are six problems on 16 pages, including two work sheets, in
More informationType Systems Winter Semester 2006
Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006 - version 1.1 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial
More informationTypes and Programming Languages. Lecture 5. Extensions of simple types
Types and Programming Languages Lecture 5. Extensions of simple types Xiaojuan Cai cxj@sjtu.edu.cn BASICS Lab, Shanghai Jiao Tong University Fall, 2016 Coming soon Simply typed λ-calculus has enough structure
More informationPart III Chapter 15: Subtyping
Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule
More informationCIS 500 Software Foundations Fall September 25
CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the
More informationCSE-321 Programming Languages 2012 Midterm
Name: Hemos ID: CSE-321 Programming Languages 2012 Midterm Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 14 15 29 20 7 15 100 There are six problems on 24 pages in this exam. The maximum score
More informationThe University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER 2012 2013 MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS Time allowed TWO hours Candidates may complete the front
More information1 Introduction. 3 Syntax
CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationCIS 500 Software Foundations Fall October 2
CIS 500 Software Foundations Fall 2006 October 2 Preliminaries Homework Results of my email survey: There was one badly misdesigned (PhD) problem and a couple of others that were less well thought through
More informationλ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods
Course 2D1453, 2006-07 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 1903-1995 Church-Turing thesis First
More informationThe Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements
CIS 500 Software Foundations Fall 2004 27 September IS 500, 27 September 1 The Lambda Calculus IS 500, 27 September 3 Announcements Homework 1 is graded. Pick it up from Cheryl Hickey (Levine 502). We
More informationCOMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein
COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Toby Murray, June Andronick, Gerwin Klein λ 1 Last time... λ calculus syntax free variables, substitution β reduction α and η conversion
More informationLecture 14: Recursive Types
Lecture 14: Recursive Types Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Programming Languages Pratikakis (CSD) Recursive Types CS546, 2018-2019 1 / 11 Motivation
More informationProgramming Languages Lecture 15: Recursive Types & Subtyping
CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)
More informationType Systems. Parametric Polymorphism. 1. Recall Let-Polymorphism. 1. Recall Let-Polymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth
Today Parametric Polymorphism Type Systems Lecture 9 Dec. 15th, 2004 Sebastian Maneth 1. Recall Let-Polymorphism 4. System F-sub 5. Properties of F-sub http://lampwww.epfl.ch/teaching/typesystems/2004
More informationProgramming Languages Lecture 14: Sum, Product, Recursive Types
CSE 230: Winter 200 Principles of Programming Languages Lecture 4: Sum, Product, Recursive Types The end is nigh HW 3 No HW 4 (= Final) Project (Meeting + Talk) Ranjit Jhala UC San Diego Recap Goal: Relate
More informationPolymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy
06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic
More informationCS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011
CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from x = 1 [Järvi], with permission of the original author, by copy & let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationMutable References. Chapter 1
Chapter 1 Mutable References In the (typed or untyped) λ-calculus, or in pure functional languages, a variable is immutable in that once bound to a value as the result of a substitution, its contents never
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationLambda Calculi With Polymorphism
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationCIS 500 Software Foundations Midterm I Answer key October 8, 2003
CIS 500 Software Foundations Midterm I Answer key October 8, 2003 Inductive Definitions Review: Recall that the function size, which calculates the total number of nodes in the abstract syntax tree of
More informationResources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in...
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationPure (Untyped) λ-calculus. Andrey Kruglyak, 2010
Pure (Untyped) λ-calculus Andrey Kruglyak, 2010 1 Pure (untyped) λ-calculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential
More informationCS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th
CS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th Name: CAS ID (e.g., abc01234@pomona.edu): I encourage you to collaborate. collaborations below. Please record your Each question is worth
More informationLambda Calculus. Lecture 4 CS /26/10
Lambda Calculus Lecture 4 CS 565 10/26/10 Pure (Untyped) Lambda Calculus The only value is a function Variables denote functions Functions always take functions as arguments Functions always return functions
More informationTyped Lambda Calculus and Exception Handling
Typed Lambda Calculus and Exception Handling Dan Zingaro zingard@mcmaster.ca McMaster University Typed Lambda Calculus and Exception Handling p. 1/2 Untyped Lambda Calculus Goal is to introduce typing
More informationCSE-321 Programming Languages 2010 Midterm
Name: Hemos ID: CSE-321 Programming Languages 2010 Midterm Score Prob 1 Prob 2 Prob 3 Prob 4 Total Max 15 30 35 20 100 1 1 SML Programming [15 pts] Question 1. [5 pts] Give a tail recursive implementation
More informationType Systems. Pierce Ch. 3, 8, 11, 15 CSE
Type Systems Pierce Ch. 3, 8, 11, 15 CSE 6341 1 A Simple Language ::= true false if then else 0 succ pred iszero Simple untyped expressions Natural numbers encoded as succ succ
More informationGoal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler.
Goal Understand what this interface means and why it matters: CS152: Programming Languages Lecture 15 Parametric Polymorphism Dan Grossman Spring 2011 type a mylist; val mt_list : a mylist val cons : a
More informationLecture 5: The Untyped λ-calculus
Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,
More informationProgramming Languages
CSE 230: Winter 2008 Principles of Programming Languages Ocaml/HW #3 Q-A Session Push deadline = Mar 10 Session Mon 3pm? Lecture 15: Type Systems Ranjit Jhala UC San Diego Why Typed Languages? Development
More informationLecture 9: Typed Lambda Calculus
Advanced Topics in Programming Languages Spring Semester, 2012 Lecture 9: Typed Lambda Calculus May 8, 2012 Lecturer: Mooly Sagiv Scribe: Guy Golan Gueta and Shachar Itzhaky 1 Defining a Type System for
More informationLambda Calculus and Type Inference
Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ August 17, 2007 Lambda Calculus and Type
More information4.5 Pure Linear Functional Programming
4.5 Pure Linear Functional Programming 99 4.5 Pure Linear Functional Programming The linear λ-calculus developed in the preceding sections can serve as the basis for a programming language. The step from
More informationConcepts of programming languages
Concepts of programming languages Lecture 5 Wouter Swierstra 1 Announcements Submit your project proposal to me by email on Friday; The presentation schedule in now online Exercise session after the lecture.
More informationCSE-321 Programming Languages 2014 Final
Name: Hemos ID: CSE-321 Programming Languages 2014 Final Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 Total Score Max 15 12 14 14 30 15 100 There are six problems on 12 pages in this exam.
More informationLambda Calculi With Polymorphism
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationProgramming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.
CMSC 330: Organization of Programming Languages Lambda Calculus Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying or tuples
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying
More informationDesign Principles of Programming Languages. Recursive Types. Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term
Design Principles of Programming Languages Recursive Types Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term Review: what have we learned so far? λ-calculus: function and data can
More informationCIS 500 Software Foundations Midterm II Answer key November 16, 2005
CIS 500 Software Foundations Midterm II Answer key November 16, 2005 Simply typed lambda-calculus The following questions refer to the simply typed lambda-calculus with booleans and error handling. The
More informationLecture 13: Subtyping
Lecture 13: Subtyping Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Programming Languages Pratikakis (CSD) Subtyping CS546, 2018-2019 1 / 15 Subtyping Usually found
More informationFormal Semantics. Aspects to formalize. Lambda calculus. Approach
Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and
More informationLambda Calculus and Extensions as Foundation of Functional Programming
Lambda Calculus and Extensions as Foundation of Functional Programming David Sabel and Manfred Schmidt-Schauß 29. September 2015 Lehrerbildungsforum Informatik Last update: 30. September 2015 Overview
More informationCOMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland
COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonly-used programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java
More informationINF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright Instructors. History Formal mathematical system Simplest programming language Intended for studying functions, recursion
More informationDesign Principles of Programming Languages. Recursive Types. Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term, 2014
Design Principles of Programming Languages Recursive Types Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term, 2014 Review: Why learn type theories? Art vs. Knowledge Art cannot be
More informationCSE505, Fall 2012, Midterm Examination October 30, 2012
CSE505, Fall 2012, Midterm Examination October 30, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at Noon. You can rip apart
More informationDependent Object Types - A foundation for Scala s type system
Dependent Object Types - A foundation for Scala s type system Draft of September 9, 2012 Do Not Distrubute Martin Odersky, Geoffrey Alan Washburn EPFL Abstract. 1 Introduction This paper presents a proposal
More informationLecture Notes on Data Representation
Lecture Notes on Data Representation 15-814: Types and Programming Languages Frank Pfenning Lecture 9 Tuesday, October 2, 2018 1 Introduction In this lecture we ll see our type system in action. In particular
More informationMore Untyped Lambda Calculus & Simply Typed Lambda Calculus
Concepts in Programming Languages Recitation 6: More Untyped Lambda Calculus & Simply Typed Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky,
More informationRecursive Types and Subtyping
Recursive Types and Subtyping #1 One-Slide Summary Recursive types (e.g., list) make the typed lambda calculus as powerful as the untyped lambda calculus. If is a subtype of then any expression of type
More informationIntroduction to System F. Lecture 18 CS 565 4/20/09
Introduction to System F Lecture 18 CS 565 4/20/09 The Limitations of F 1 (simply-typed λ- calculus) In F 1 each function works exactly for one type Example: the identity function id = λx:τ. x : τ τ We
More informationCS 4110 Programming Languages & Logics. Lecture 28 Recursive Types
CS 4110 Programming Languages & Logics Lecture 28 Recursive Types 7 November 2014 Announcements 2 Foster office hours 11-12pm Guest lecture by Fran on Monday Recursive Types 3 Many languages support recursive
More informationMidterm 1. CMSC 430 Introduction to Compilers Spring Instructions Total 100. Name: March 14, 2012
Name: Midterm 1 CMSC 430 Introduction to Compilers Spring 2012 March 14, 2012 Instructions This exam contains 8 pages, including this one. Make sure you have all the pages. Write your name on the top of
More informationλ-calculus Lecture 1 Venanzio Capretta MGS Nottingham
λ-calculus Lecture 1 Venanzio Capretta MGS 2018 - Nottingham Table of contents 1. History of λ-calculus 2. Definition of λ-calculus 3. Data Structures 1 History of λ-calculus Hilbert s Program David Hilbert
More informationLambda Calculus. Concepts in Programming Languages Recitation 6:
Concepts in Programming Languages Recitation 6: Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming
More informationCS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e
More informationCIS 500 Software Foundations Fall December 4
CIS 500 Software Foundations Fall 2006 December 4 Administrivia Homework 11 Homework 11 is currently due on Friday. Should we make it due next Monday instead? More on Evaluation Contexts Progress for FJ
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationCS4215 Programming Language Implementation. Martin Henz
CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming
More informationLesson 4 Typed Arithmetic Typed Lambda Calculus
Lesson 4 Typed Arithmetic Typed Lambda 1/28/03 Chapters 8, 9, 10 Outline Types for Arithmetic types the typing relation safety = progress + preservation The simply typed lambda calculus Function types
More informationMLW. Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. March 26, Radboud University Nijmegen
1 MLW Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky Radboud University Nijmegen March 26, 2012 inductive types 2 3 inductive types = types consisting of closed terms built from constructors
More informationThe University of Nottingham
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER 2013-2014 G54FOP FOUNDATIONS OF PROGRAMMING Time allowed 2 hours Candidates may complete the front cover of their
More informationDenotational Semantics. Domain Theory
Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning
More informationExercise 1 (2+2+2 points)
1 Exercise 1 (2+2+2 points) The following data structure represents binary trees only containing values in the inner nodes: data Tree a = Leaf Node (Tree a) a (Tree a) 1 Consider the tree t of integers
More informationPolymorphism. Lecture 19 CS 565 4/17/08
Polymorphism Lecture 19 CS 565 4/17/08 The Limitations of F 1 (simply-typed λ- calculus) In F 1 each function works exactly for one type Example: the identity function id = λx:τ. x : τ τ We need to write
More informationDependent Object Types - A foundation for Scala's type system
Dependent Object Types - A foundation for Scala's type system Draft of January 14, 2010 Do Not Distrubute Martin Odersky, Georey Alan Washburn EPFL Abstract. 1 Introduction This paper presents a proposal
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 14 Tuesday, March 24, 2015 1 Parametric polymorphism Polymorph means many forms. Polymorphism is the ability of
More informationFormal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack
Formal Semantics Prof. Clarkson Fall 2015 Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack Review Previously in 3110: simple interpreter for expression language: abstract syntax
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Spring 2017 1 Review A lambda calculus expression is defined as e ::= x variable λx.e abstraction (fun def) e e application
More informationOverview. A normal-order language. Strictness. Recursion. Infinite data structures. Direct denotational semantics. Transition semantics
Overview A normal-order language Strictness Recursion Infinite data structures Direct denotational semantics Transition semantics Lazy (call-by-need) evaluation and its semantics A Normal-Order Language
More informationTypes and Programming Languages. Lecture 8. Recursive type
Types and Programming Languages Lecture 8. Recursive type Xiaojuan Cai cxj@sjtu.edu.cn BASICS Lab, Shanghai Jiao Tong University Fall, 2016 List[T] List[T] is a type constructor whose elements are lists
More informationReview. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals
Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:
More informationRecursive Types and Subtyping
Recursive Types and Subtyping #1 One-Slide Summary Recall: Recursive types (e.g., τ list) make the typed lambda calculus as powerful as the untyped lambda calculus. If τ is a subtype of σ then any expression
More informationType Systems Winter Semester 2006
Type Systems Winter Semester 2006 Week 9 December 13 December 13, 2006 - version 1.0 Plan PREVIOUSLY: unit, sequencing, let, pairs, sums TODAY: 1. recursion 2. state 3.??? NEXT: exceptions? NEXT: polymorphic
More informationThe Substitution Model
The Substitution Model Prof. Clarkson Fall 2017 Today s music: Substitute by The Who Review Previously in 3110: simple interpreter for expression language abstract syntax tree (AST) evaluation based on
More informationIntroduction to the λ-calculus
Announcements Prelim #2 issues: o Problem 5 grading guide out shortly o Problem 3 (hashing) issues Will be on final! Friday RDZ office hours are 11-12 not 1:30-2:30 1 Introduction to the λ-calculus Today
More informationCIS 500 Software Foundations. Final Exam. May 3, Answer key
CIS 500 Software Foundations Final Exam May 3, 2012 Answer key This exam includes material on the Imp language and the simply-typed lambda calculus. Some of the key definitions are repeated, for easy reference,
More informationCMSC 330: Organization of Programming Languages. Lambda Calculus Encodings
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC330 Spring 2018 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!
More informationWhereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions
Whereweare CS-XXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave
More informationOrnaments in ML. Thomas Williams, Didier Rémy. April 18, Inria - Gallium
Ornaments in ML Thomas Williams, Didier Rémy Inria - Gallium April 18, 2017 1 Motivation Two very similar functions let rec add m n = match m with Z n S m S (add m n) let rec append ml nl = match ml with
More informationActivity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?
Activity CSCI 334: Principles of Programming Languages Lecture 4: Fundamentals II Write a function firsts that, when given a list of cons cells, returns a list of the left element of each cons. ( (a. b)
More informationHarvard School of Engineering and Applied Sciences Computer Science 152
Harvard School of Engineering and Applied Sciences Computer Science 152 Lecture 17 Tuesday, March 30, 2010 1 Polymorph means many forms. Polymorphism is the ability of code to be used on values of different
More information