Lambda Calculi With Polymorphism
|
|
- Alberta Charles
- 5 years ago
- Views:
Transcription
1 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 based on [Pierce] as the underlying textbook. x(1).!x(1) x.set(1) Programming Paradigms and Formal Semantics Lambda Calculi With Polymorphism Ralf Lämmel [Järvi] Slides by J. Järvi: Programming Languages, CPSC TAMU (2009) [Pierce] B.C. Pierce: Types and Programming Languages, MIT Press, 2002 >1h
2 Polymorphism -- Why? What s the identity function? In the simple typed lambda calculus, this depends on the type! Examples λx:bool. x λx:nat. x λx:bool bool. x λx:bool nat. x
3 Polymorphism Polymorphic function a function that accepts many types of arguments. Kinds of polymorphism Parametric polymorphism ( all types ) Bounded polymorphism ( subtypes ) Ad-hoc polymorphism ( some types ) System F [Girard72,Reynolds74] = (simply-typed) lambda calculus + type abstraction & application 195
4 Polymorphism Kinds of polymorphism Parametric polymorphism ( all types ) Bounded polymorphism ( subtypes ) Ad-hoc polymorphism ( some types ) 196
5 System F -- Syntax tax t ::=x v tt t[t ] v ::=λx :T.t ΛX.t T ::=X T T X.T Type application Type abstraction Polymorphic type 197
6 System F -- Typing rules T-Variable x : T Γ Γ x : T T-Abstraction Γ, x : T u : U Γ λx : T.u : T U T-Application Γ t : U T Γ tu: T Γ u : U T-TypeAbstraction Γ, X t : T Γ ΛX.t : X.T T-TypeApplication Γ t : X.T Γ t[t 1 ]:[T 1 /X ]T 198
7 System F -- Evaluation rules E-AppFun t 1 t 1 t 1 t 2 t 1 t 2 E-TypeApp E-TypeApp t 1 t 1 t 1 [T ] t 1 [T ] E-AppArg t t vt vt E-AppAbs (λx :T.t) v [v/x]t E-TypeAppAbs (ΛX.t)[T ] [T /X ]t 199
8 Type abstraction and application Evaluation E-TypeApp t 1 t 1 t 1 [T ] t 1 [T ] E-TypeAppAbs (ΛX.t)[T ] [T /X ]t Typing T-TypeAbstraction Γ, X t : T Γ ΛX.t : X.T T-TypeApplication Γ t : X.T Γ t[t 1 ]:[T 1 /X ]T Type variables are in the environment. Type variables are subject to (implicit) renaming. 200
9 Examples Term id =ΛX.λx :X.x id[bool] id[bool] true id true Type : X.X X : bool bool : bool type error There is no type-argument deduction at this point. 201
10 Instantiated with nat The doubling function double=λx.λf :X X.λx :X.f (f x) double_nat = double [nat] : (nat nat) nat nat Instantiated with nat nat double_nat_arrow_nat = double [nat nat] : ((nat nat) nat nat) (nat nat) nat nat Invoking double double [nat] (λx : nat.succ (succ x)) 5 * 9 202
11 Self application Not typeable in the simply-typed lambda calculus λx :?. x x Typeable in System F selfapp = λx : X.X X.x [ X.X X] x selfapp : ( X.X X) ( X.X X) 203
12 The fix operator (Y) Not typeable in the simply-typed lambda calculus Typeable in System F. fix : X.(X X) X Encodeable in System F with recursive types. fix =? See [TAPL] 204
13 Remember lists? (in the simply-typed lambda calculus) New type:... List T New syntax:... nil[t] const[t] t t isnil[t] t head[t] t tail[t] t New congruence rules, e.g.: New computation rules, e.g.: t 1 t 1 cons[t ] t 1 t 2 cons[t ] t 1 t 2 head[s] (cons[t ] v 1 v 2 ) v 1 New typing rules, e.g.: Γ t : List T Γ head[t ] t : T 205
14 Lists in System F Types of list operations nil : X. List X cons : X.X List X List X isnil : X.List X bool head : X.List X X tail : X.List X List X List T can be encoded. X. (T U U) U U (see [TAPL] Chapter 23.4; requires fix) 206
15 Meaning of forall In a universal type, X...., we quantify over all types. Predicative polymorphism X ranges over simple types. Polymorphic types are type schemes. Type inference is decidable. Impredicative polymorphism X also ranges over polymorphic types. Type inference is undecidable. type:type polymorphism X ranges over all types, including itself. Computations on types are expressible. Type checking is undecidable. 207
16 Limits of type schemes Consider the polymorphic identity function: id : X. X X id = ΛX.λx : X.x Use id to construct a pair of Boolean and String: pairid : (Bool, String) pairid = (id true, id true ) Abstract over id: pairapply : ( X. X X) (Bool, String) pairapply = λf : X. X X. (f true, f true ) Type application left implicit. Argument must be polymorphic! 208
17 Existential types A means for information hiding and abstraction. Remember predicate logic. x.p(x) ( x. P(x)) Existential types can be encoded as universal types; see [TAPL]. Syntax: { X, T} 209
18 vs. t of type X.T Logical view: t has value of type [S/X]T for any S. Operational view: t is a mapping from type S to a term of type [S/X]T. t of type { X, T} Logical view: t has value of type [S/X]T for some S. Operational view: t is a pair of a type S and a term u of type [S/X]T. S is hidden. Notation: { *S, u } 210
19 Constructing existentials { *S, u } { *S, u } should be considered a package (module). The type system makes sure that S is inaccessible from outside. Consider the following package: p = {*nat, {a = 1, b = λx:nat. pred x}} Multiple types make sense: { X, {a:x, b:x X} } { X, {a:x, b:x nat} } Existential types require programmer annotation. 211
20 Annotating existentials p = {*nat, {a = 1, b = λx:nat. pred x}} as { X, {a:x, b:x X}} p has type: { X, {a:x, b:x X}} p = {*nat, {a = 1, b = λx:nat. pred x}} as { X, {a:x, b:x nat}} p has type: { X, {a:x, b:x nat}} 212
21 Information hiding Packages with different representation types can have the same existential type. p1 = {*nat, {a = 1, b = λx:nat. iszero x}} as { X, {a:x, b:x bool}} p2 = {*bool, {a = false, b = λx:bool. if x then false else true}} as { X, {a:x, b:x bool}} 213
22 Unpacking existentials (Opening package, importing module) The existential becomes available. The representation type is not accessible. Only the capabilities of the existential type are accessible. Example: let {X,t} = p2 in (t.b t.a) * true : bool 214
23 Typing rules T-PackExistential Γ t :[U/X ]T Γ { U, t} as { X, T } : { X, T } T-UnpackExistential Γ t 1 : { X, T 12 } Γ, X, x : T 12 t 2 : T 2 Substitution checks that the abstracted type of t can be instantiated with the hidden type to the actual type of t. Only expose abstract type! Γ let {X, x} = t 1 in t 2 : T 2 215
24 Evaluation rules E-Unpack E-Pack t t { T, t} as U { T, t } as U t 1 t 1 let {X, x} = t 1 in t 2 let {X, x} = t 1 in t 2 E-UnpackPack let {X, x} =({ T, v} as U) in t 2 [T /X ][v/x]t 2 The hidden type is known to the evaluation, but the type system did not expose it; so t2 cannot exploit it. 216
25 Illustration of information hiding The representation type must not leak / must remain abstract. t = {*nat, {a = 1, b = λx:nat. iszero x} as { X, {a:x, b:x bool}}} let {X,x} = t in pred x.a // Type error! The type can be used in the scope of the unpacked package. let {X, x} = t in (λ y:x. x.b y) x.a * false : bool The type cannot be free in the resulting type: let {X, x} = t in x.a // Type error! 217
26 Polymorphism Kinds of polymorphism Parametric polymorphism ( all types ) Bounded polymorphism ( subtypes ) Ad-hoc polymorphism ( some types ) 218
27 What is subtyping anyway? We say S is a subtype of T. S <: T Substitutability (Liskov substitution principle): For each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2. Practical type checking: Any expression of type S can be used in any context that expects an expression of type T, and no type error will occur. 219
28 Why subtyping Function in near-to-c: void foo( struct { int a; } r) { r.a = 0; } Function application in near-to-c: struct K { int a; int b: } K k; foo(k); // error Intuitively, it is safe to pass k. Subtyping allows it. 220
29 Subsumption Subsititutability is captured with the subsumption rule: Γ t : U U <: T Γ t : T Adding this rules requires revisiting other rules. Subtyping is a crosscutting extension. 221
30 Subtyping in simplified setting Simply-typed lambda calculus + records Booleans integers Structural subtyping for records 222
31 Subtyping for records Order of fields does not matter. S-RecordPermutation {l i : T i i 1...n } is a permutation of {k j : U j j 1...n } {l i : T i i 1...n } <: {k j : U j j 1...n } Example: {key : bool, value : int} <: {value : int, key : bool} 223
32 Subtyping for records We can always add new fields in the end. S-RecordNewFields {l i : T i i 1...n+k } <: {l i : T i i 1...n } Example: {key : bool, value : int, map : int int} <: {key : bool, value : int} 224
33 Subtyping for records We can subject the fields to subtyping. S-RecordElements for each i T i <: U i {l i : T i i 1...n } <: {l i : U i i 1...n } Example: {field1 : bool, field2 : {val : bool}} <: {field1 : bool, field2 : {}} 225
34 General rules for subtyping Reflexivity T <: T Transitivity T <: U T <: V U <: V Example Prove that {a : bool, b : int, c : {l : int}} <: {c : {}} 226
35 Subtyping and functions Assume that a function f of the following type is expected: f :T U Then it is safe to pass an actual function g such that: g :T U T <: T (g expects less fields than f) U <: U (g gives more fields than f) 227
36 Subtyping and functions Function subtyping covariant on return types contravariant on parameter types T 2 <: T 1 U 2 <: U 1 T 1 U 2 <: T 2 U 1 228
37 Supertype of everything T ::=... top The most general type T <: top The supertype of all types 229
38 Remember type annotation? Syntax: t ::=... t as T Typing rule: Γ t : T Γ t as T : T Evaluation rules: t u t as T u as T v as T v 230
39 Annotation is up-casting Illustrative type derivation: Example:.. Γ t : U U <: T Γ t : T Γ t as T : T (λx :bool.{a = x, b = false}) true as {a : bool} 231
40 Type annotation with down-casting Typing rule: Γ t : U Γ t as T : T Potentially too liberal Evaluation rules: t u t as T u as T Runtime type check v : T v as T v 232
41 Typing rules so far T-Record for each i, Γ t i : T i Γ {l i = t i i 1...n } : {l i : T i i 1...n } T-Projection Γ t : {l i : T i i 1...n } Γ t.l j : T j T-Subsumption Γ t : U U <: T Γ t : T T-Variable x : T Γ Γ x : T T-Abstraction Γ, x : T u : U Γ λx : T.u : T U T-Application Γ t : U T Γ tu: T Γ u : U T-True true : bool T-False false : bool 233
42 Reminder A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute. [B.C. Pierce] 234
43 Violation of syntax direction Consider an application: t u where t of type U V and u of type S. Type checker must figure out that S <: U. This is hard with the rules so far. The rules need to be redesigned. 235
44 Analysis of subsumption The term in the conclusion can be anything. It is just a metavariable. T-Subsumption Γ t : U U <: T Γ t : T E.g. which rule should you apply here? Γ (λx :U.t) :? T-Abstraction or T-Subsumption? 236
45 Analysis of transitivity S-Transitivity T <: U T <: V U does not appear in conclusion. U <: V Thus, to show T <: V, we need to guess a U. For instance, try to show the following: {y :int, x :int} <: {x :int} 237
46 Analysis of transitivity What is the purpose of transitivity? Chaining together separate subtyping rules for records! S-RecordPermutation {l i : T i i 1...n } is a permutation of {k j : U j j 1...n } {l i : T i i 1...n } <: {k j : U j j 1...n } S-RecordElements for each i T i <: U i {l i : T i i 1...n } <: {l i : U i i 1...n } S-RecordNewFields {l i : T i i 1...n+k } <: {l i : T i i 1...n } 238
47 Algorithmic subtyping Replace all previous rules by a single rule. S-Record {l i i 1...n } {k j j 1...m } l i = k j implies U i <: T j e d need to prove: {k j : U j i 1...m } <: {l i : T i i 1...n } Correctness / completeness of new rule can be shown. Maintain extra rule for function types. } { S-Function T 1 <: T 2 U 1 <: U 2 T 2 U 1 <: T 1 U 2 239
48 Algorithmic subtyping The subsumption rule is still not syntax-directed. The rule is essentially used in function application. Express subsumption through an extra premise. Retire subsumption rule. T-Application Γ t : U T Γ u : V V <: U Γ tu: T 240
49 Summary: Lambdas with somewhat sexy types Done:,, <:,... Not done: μ,... Prepping: Types and Programming Languages Chapters 15, 16, 22, 23, 24 Lab: The Typed Lambda Calculus in Prolog Outlook: Functional programming with Haskell Denotational semantics 241
Lambda 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 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 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 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 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 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 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 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 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 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 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 informationCIS 500 Software Foundations Fall December 6
CIS 500 Software Foundations Fall 2006 December 6 Administrivia Administrivia No recitations this week Extra office hours will be posted to the class mailing list Exam: Wednesday, Dec 20, 9 11 Location:
More informationAdministrivia. Existential Types. CIS 500 Software Foundations Fall December 6. Administrivia. Motivation. Motivation
CIS 500 Software Foundations Fall 2006 Administrivia December 6 Administrivia No recitations this week Extra office hours will be posted to the class mailing list Exam: Wednesday, Dec 20, 9 11 Location:
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 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 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 informationSecond-Order Type Systems
#1 Second-Order Type Systems Homework 5 Summary Student : 37.9704 Student : 44.4466 ORIGINAL : 50.2442 Student : 50.8275 Student : 50.8633 Student : 50.9181 Student : 52.1347 Student : 52.1633 Student
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 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 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 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 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 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 informationLesson 11 Universal Types. Universal Types and System F
Lesson 11 Universal Types 2/28 Chapter 23 Universal Types and System F Varieties of polymorphism System F Examples Basic properties Erasure Evaluation issues Parametricity Impredicativity Lesson 11: Universal
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 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 informationInductive Definitions, continued
1 / 27 Inductive Definitions, continued Assia Mahboubi Jan 7th, 2016 2 / 27 Last lecture Introduction to Coq s inductive types: Introduction, elimination and computation rules; Twofold implementation :
More informationINF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright Instructors. What is a Data Type? A type is a collection of computational entities that share some common property Programming
More informationSymmetry in Type Theory
Google May 29th, 2012 What is Symmetry? Definition Symmetry: Two or more things that initially look distinct, may actually be instances of a more general underlying principle. Why do we care? Simplicity.
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 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 informationSubtyping. Lecture 13 CS 565 3/27/06
Subtyping Lecture 13 CS 565 3/27/06 Polymorphism Different varieties of polymorphism: Parametric (ML) type variables are abstract, and used to encode the fact that the same term can be used in many different
More informationINF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes
INF 212/CS 253 Type Systems Instructors: Harry Xu Crista Lopes What is a Data Type? A type is a collection of computational entities that share some common property Programming languages are designed to
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 informationArbitrary-rank polymorphism in (GHC) Haskell
Arbitrary-rank polymorphism in (GHC) Haskell CAS 743 Stephen Forrest 20 March 2006 Damas-Milner Type System A Damas-Milner type system (also called Hindley-Milner) is a traditional type system for functional
More informationCS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus
CS 4110 Programming Languages & Logics Lecture 17 Programming in the λ-calculus 10 October 2014 Announcements 2 Foster Office Hours 11-12 Enjoy fall break! Review: Church Booleans 3 We can encode TRUE,
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 informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 03: Bare-Bones Haskell Continued: o Function Application = Rewriting by Pattern Matching o Haskell
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 informationLecture 9: More Lambda Calculus / Types
Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Pure Lambda Calculus Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete
More information- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.
Pure Lambda Calculus Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete
More informationOfficial Survey. Cunning Plan: Focus On Objects. The Need for a Calculus. Object Calculi Summary. Why Not Use λ-calculus for OO?
Modeling and Understanding Object-Oriented Oriented Programming Official Survey Please fill out the Toolkit course survey 40142 CS 655-1 Apr-21-2006 Midnight May-04-2006 9am Why not do it this evening?
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 informationThe lambda calculus (An introduction)
The lambda calculus (An introduction) Ralf Lämmel Software Language Engineering Team University of Koblenz-Landau http://www.softlang.org/ Dependencies: Tree-based abstract syntax Operational semantics
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 informationLet Arguments Go First
Let Arguments Go First Ningning Xie and Bruno C. d. S. Oliveira The University of Hong Kong {nnxie,bruno}@cs.hku.hk Abstract. Bi-directional type checking has proved to be an extremely useful and versatile
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 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 informationPolymorphism and System-F (OV)
Polymorphism and System-F (OV) Theorie der Programmierung SoSe 2014 FAU the occurrence of something in several different forms Polymorphism? Polymorphic systems Type systems that allow a single piece of
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 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 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 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 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 information(Advanced) topics in Programming Languages
Spring 2012 (Advanced) topics in Programming Languages Instructor: Mooly Sagiv TA: Shachar Itzhaky http://www.cs.tau.ac.il/~msagiv/courses/apl12.html Inspired by John Mitchell CS 242 Compilation course
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 informationExercise 1 ( = 22 points)
1 Exercise 1 (4 + 3 + 4 + 5 + 6 = 22 points) The following data structure represents polymorphic lists that can contain values of two types in arbitrary order: data DuoList a b = C a (DuoList a b) D b
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 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 informationConsistent Subtyping for All
Consistent Subtyping for All Ningning Xie Xuan Bi Bruno C. d. S. Oliveira 11 May, 2018 The University of Hong Kong 1 Background There has been ongoing debate about which language paradigm, static typing
More informationFunctional Languages and Higher-Order Functions
Functional Languages and Higher-Order Functions Leonidas Fegaras CSE 5317/4305 L12: Higher-Order Functions 1 First-Class Functions Values of some type are first-class if They can be assigned to local variables
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 informationCalculus of Inductive Constructions
Calculus of Inductive Constructions Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Calculus of Inductive Constructions
More informationType Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters
Today Type Systems 1. Organizational Matters 2. What is this course about? 3. Where do types come from? 4. Def. of the small language Expr. Its syntax and semantics. Lecture 1 Oct. 20th, 2004 Sebastian
More informationAdvances in Programming Languages
Advances in Programming Languages Lecture 4: Higher Polymorphism Ian Stark School of Informatics The University of Edinburgh Friday 30 September 2016 Semester 1 Week 2 https://blog.inf.ed.ac.uk/apl16 Topic:
More informationTradeoffs. CSE 505: Programming Languages. Lecture 15 Subtyping. Where shall we add useful completeness? Where shall we add completeness?
Tradeoffs CSE 505: Programming Languages Lecture 15 Subtyping Zach Tatlock Autumn 2017 Desirable type system properties (desiderata): soundness - exclude all programs that get stuck completeness - include
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 informationThis section is primarily based on Principles of Type Refinement, Noam Zeilberger,
1 Refinement Types This section is primarily based on Principles of Type Refinement, Noam Zeilberger, OPLSS 2016 The concept of refinement types is quite general. So general, in fact, that it is not immediately
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 informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationThe Untyped Lambda Calculus
CS738: Advanced Compiler Optimizations The Untyped Lambda Calculus Amey Karkare karkare@cse.iitk.ac.in http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur Reference Book Types and Programming
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
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/ October 13, 2004 Lambda Calculus and Type
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 informationAutomated Reasoning. Natural Deduction in First-Order Logic
Automated Reasoning Natural Deduction in First-Order Logic Jacques Fleuriot Automated Reasoning Lecture 4, page 1 Problem Consider the following problem: Every person has a heart. George Bush is a person.
More information1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.
1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered
More informationCS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106
CS 565: Programming Languages Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106 Administrivia Who am I? Course web page http://www.cs.purdue.edu/homes/peugster/cs565spring08/ Office hours By appointment Main
More informationTypes for References, Exceptions and Continuations. Review of Subtyping. Γ e:τ τ <:σ Γ e:σ. Annoucements. How s the midterm going?
Types for References, Exceptions and Continuations Annoucements How s the midterm going? Meeting 21, CSCI 5535, Spring 2009 2 One-Slide Summary Review of Subtyping If τ is a subtype of σ then any expression
More informationGraphical Untyped Lambda Calculus Interactive Interpreter
Graphical Untyped Lambda Calculus Interactive Interpreter (GULCII) Claude Heiland-Allen https://mathr.co.uk mailto:claude@mathr.co.uk Edinburgh, 2017 Outline Lambda calculus encodings How to perform lambda
More informationGADTs. Wouter Swierstra. Advanced functional programming - Lecture 7. Faculty of Science Information and Computing Sciences
GADTs Advanced functional programming - Lecture 7 Wouter Swierstra 1 Today s lecture Generalized algebraic data types (GADTs) 2 A datatype data Tree a = Leaf Node (Tree a) a (Tree a) This definition introduces:
More informationCOS 320. Compiling Techniques
Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly
More informationPierce Ch. 3, 8, 11, 15. Type Systems
Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 04: Basic Haskell Continued o Polymorphic Types o Type Inference with Polymorphism o Standard
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 informationBasic Foundations of Isabelle/HOL
Basic Foundations of Isabelle/HOL Peter Wullinger May 16th 2007 1 / 29 1 Introduction into Isabelle s HOL Why Type Theory Basic Type Syntax 2 More HOL Typed λ Calculus HOL Rules 3 Example proof 2 / 29
More informationCOMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking
Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review
More information上海交通大学试卷 ( 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 informationProgramming Languages Assignment #7
Programming Languages Assignment #7 December 2, 2007 1 Introduction This assignment has 20 points total. In this assignment, you will write a type-checker for the PolyMinML language (a language that is
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 informationG Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,
More informationLast class. CS Principles of Programming Languages. Introduction. Outline
Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting
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 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 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 informationFeatherweight Java (FJ)
x = 1 let x = 1 in... x(1).!x(1) x.set(1) Programming Language Theory Featherweight Java (FJ) Ralf Lämmel This lecture is based on David Walker s lecture: Computer Science 441, Programming Languages, Princeton
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Tuesday, February 19, 2013 The lambda calculus (or λ-calculus) was introduced by Alonzo Church and Stephen Cole Kleene in
More informationTypes, Type Inference and Unification
Types, Type Inference and Unification Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Cornell CS 6110 Summary (Functional Programming) Lambda Calculus Basic ML Advanced ML: Modules, References,
More informationType Checking and Type Inference
Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled
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 information