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

Size: px
Start display at page:

Transcription

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

2 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our core model But will soon enrich with other common primitives This lecture: Motivation for type systems What a type system is designed to do and not do Definition of stuckness, soundness, completeness, etc. The Simply-Typed Lambda Calculus A basic and natural type system Starting point for more expressiveness later Next lecture: Prove Simply-Typed Lambda Calculus is sound Dan Grossman CS-XXX 2012, Lecture 9 2

3 Review: L-R CBV Lambda Calculus e ::= λx. e x e e v ::= λx. e Implicit systematic renaming of bound variables α-equivalence on expressions ( the same term ) e e (λx. e) v e[v/x] e 1 e 1 e 1 e 2 e 1 e 2 e 2 e 2 v e 2 v e 2 e 1 [e 2 /x] = e 3 x[e/x] = e y x y[e/x] = y e 1 [e/x] = e 1 e 2 [e/x] = e 2 (e 1 e 2 )[e/x] = e 1 e 2 e 1 [e/x] = e 1 y x y F V (e) (λy. e 1 )[e/x] = λy. e 1 Dan Grossman CS-XXX 2012, Lecture 9 3

4 Introduction to Types Naive thought: More powerful PLs are always better Be Turing Complete (e.g., Lambda Calculus or x86 Assembly) Have really flexible features (e.g., lambdas) Have conveniences to keep programs short If this is the only metric, types are a step backward Whole point is to allow fewer programs A filter between abstract syntax and compiler/interpreter Fewer programs in language means less for a correct implementation So if types are a great idea, they must help with other desirable properties for a PL... Dan Grossman CS-XXX 2012, Lecture 9 4

5 Why types? (Part 1) 1. Catch simple mistakes early, even for untested code Example: if applied to mkpair Even if some too-clever programmer meant to do it Even though decidable type systems must be conservative Dan Grossman CS-XXX 2012, Lecture 9 5

6 Why types? (Part 1) 1. Catch simple mistakes early, even for untested code Example: if applied to mkpair Even if some too-clever programmer meant to do it Even though decidable type systems must be conservative 2. (Safety) Prevent getting stuck (e.g., x v) Ensure execution never gets to a meaningless state But meaningless depends on the semantics Each PL typically makes some things type errors (again being conservative) and others run-time errors Dan Grossman CS-XXX 2012, Lecture 9 5

7 Why types? (Part 1) 1. Catch simple mistakes early, even for untested code Example: if applied to mkpair Even if some too-clever programmer meant to do it Even though decidable type systems must be conservative 2. (Safety) Prevent getting stuck (e.g., x v) Ensure execution never gets to a meaningless state But meaningless depends on the semantics Each PL typically makes some things type errors (again being conservative) and others run-time errors 3. Enforce encapsulation (an abstract type) Clients can t break invariants Clients can t assume an implementation Requires safety, meaning no stuck states that corrupt run-time (e.g., C/C++) Can enforce encapsulation without static types, but types are a particularly nice way Dan Grossman CS-XXX 2012, Lecture 9 5

8 Why types? (Part 2) 4. Assuming well-typedness allows faster implementations Smaller interfaces enable optimizations Don t have to check for impossible states Orthogonal to safety (e.g., C/C++) Dan Grossman CS-XXX 2012, Lecture 9 6

9 Why types? (Part 2) 4. Assuming well-typedness allows faster implementations Smaller interfaces enable optimizations Don t have to check for impossible states Orthogonal to safety (e.g., C/C++) 5. Syntactic overloading Have symbol lookup depend on operands types Only modestly interesting semantically Late binding (lookup via run-time types) more interesting Dan Grossman CS-XXX 2012, Lecture 9 6

10 Why types? (Part 2) 4. Assuming well-typedness allows faster implementations Smaller interfaces enable optimizations Don t have to check for impossible states Orthogonal to safety (e.g., C/C++) 5. Syntactic overloading Have symbol lookup depend on operands types Only modestly interesting semantically Late binding (lookup via run-time types) more interesting 6. Detect other errors via extensions Often via a type-and-effect system Deep similarities in analyses suggest type systems a good way to think-about/define/prove what you re checking Uncaught exceptions, tainted data, non-termination, IO performed, data races, dangling pointers,... Dan Grossman CS-XXX 2012, Lecture 9 6

11 Why types? (Part 2) 4. Assuming well-typedness allows faster implementations Smaller interfaces enable optimizations Don t have to check for impossible states Orthogonal to safety (e.g., C/C++) 5. Syntactic overloading Have symbol lookup depend on operands types Only modestly interesting semantically Late binding (lookup via run-time types) more interesting 6. Detect other errors via extensions Often via a type-and-effect system Deep similarities in analyses suggest type systems a good way to think-about/define/prove what you re checking Uncaught exceptions, tainted data, non-termination, IO performed, data races, dangling pointers,... We ll focus on (1), (2), and (3) and maybe (6) Dan Grossman CS-XXX 2012, Lecture 9 6

12 What is a type system? Er, uh, you know it when you see it. Some clues: A decidable (?) judgment for classifying programs E.g., e1 + e 2 has type int if e 1, e 2 have type int (else no type) A sound (?) abstraction of computation E.g., if e 1 + e 2 has type int, then evaluation produces an int (with caveats!)) Fairly syntax directed Non-example (?): e terminates within 100 steps Particularly fuzzy distinctions with abstract interpretation Possible topic for a later lecture Often a more natural framework for flow-sensitive properties Types often more natural for higher-order programs This is a CS-centric, PL-centric view. Foundational type theory has more rigorous answers Later lecture: Typed PLs are like proof systems for logics Dan Grossman CS-XXX 2012, Lecture 9 7

13 Plan for 3ish weeks Simply typed λ calculus (Syntactic) Type Soundness (i.e., safety) Extensions (pairs, sums, lists, recursion) Break for the Curry-Howard isomorphism; continuations; midterm Subtyping Polymorphic types (generics) Recursive types Abstract types Effect systems Homework: Adding back mutation Omitted: Type inference Dan Grossman CS-XXX 2012, Lecture 9 8

14 Adding constants Enrich the Lambda Calculus with integer constants: Not stricly necessary, but makes types seem more natural e ::= λx. e x e e c v ::= λx. e c No new operational-semantics rules since constants are values We could add + and other primitives Then we would need new rules (e.g., 3 small-step for +) Alternately, parameterize programs by primitives: λplus. λtimes.... e Like Pervasives in OCaml A great way to keep language definitions small Dan Grossman CS-XXX 2012, Lecture 9 9

15 Stuck Key issue: can a program get stuck (reach a bad state)? Definition: e is stuck if e is not a value and there is no e such that e e Definition: e can get stuck if there exists an e such that e e and e is stuck In a deterministic language, e gets stuck Most people don t appreciate that stuckness depends on the operational semantics Inherent given the definitions above Dan Grossman CS-XXX 2012, Lecture 9 10

16 What s stuck? Given our language, what are the set of stuck expressions? Note: Explicitly defining the stuck states is unusual e ::= λx. e x e e c v ::= λx. e c (λx. e) v e[v/x] e 1 e 1 e 1 e 2 e 1 e 2 e 2 e 2 v e 2 v e 2 (Hint: The full set is recursively defined.) S ::= Dan Grossman CS-XXX 2012, Lecture 9 11

17 What s stuck? Given our language, what are the set of stuck expressions? Note: Explicitly defining the stuck states is unusual e ::= λx. e x e e c v ::= λx. e c (λx. e) v e[v/x] e 1 e 1 e 1 e 2 e 1 e 2 e 2 e 2 v e 2 v e 2 (Hint: The full set is recursively defined.) S ::= x c v S e v S Dan Grossman CS-XXX 2012, Lecture 9 11

18 What s stuck? Given our language, what are the set of stuck expressions? Note: Explicitly defining the stuck states is unusual e ::= λx. e x e e c v ::= λx. e c (λx. e) v e[v/x] e 1 e 1 e 1 e 2 e 1 e 2 e 2 e 2 v e 2 v e 2 (Hint: The full set is recursively defined.) S ::= x c v S e v S Note: Can have fewer stuck states if we add more rules Example: Javascript Example: c v v In unsafe languages, stuck states can set the computer on fire Dan Grossman CS-XXX 2012, Lecture 9 11

19 Soundness and Completeness A type system is a judgment for classifying programs accepts a program if some complete derivation gives it a type, else rejects A sound type system never accepts a program that can get stuck No false negatives A complete type system never rejects a program that can t get stuck No false positives It is typically undecidable whether a stuck state can be reachable Corollary: If we want an algorithm for deciding if a type system accepts a program, then the type system cannot be sound and complete We ll choose soundness, try to reduce false positives in practice Dan Grossman CS-XXX 2012, Lecture 9 12

20 Wrong Attempt τ ::= int fn e : τ λx. e : fn c : int e 1 : fn e 1 e 2 : int e 2 : int Dan Grossman CS-XXX 2012, Lecture 9 13

21 Wrong Attempt τ ::= int fn e : τ λx. e : fn c : int e 1 : fn e 1 e 2 : int e 2 : int 1. NO: can get stuck, e.g., (λx. y) 3 2. NO: too restrictive, e.g., (λx. x 3) (λy. y) 3. NO: types not preserved, e.g., (λx. λy. y) 3 Dan Grossman CS-XXX 2012, Lecture 9 13

22 Getting it right 1. Need to type-check function bodies, which have free variables 2. Need to classify functions using argument and result types For (1): Γ ::= Γ, x : τ and Γ e : τ Require whole program to type-check under empty context For (2): τ ::= int τ τ An infinite number of types: int int, (int int) int, int (int int),... Concrete syntax note: is right-associative, so τ 1 τ 2 τ 3 is τ 1 (τ 2 τ 3 ) Dan Grossman CS-XXX 2012, Lecture 9 14

23 STLC Type System τ ::= int τ τ Γ ::= Γ, x:τ Γ e : τ Γ c : int Γ x : Γ(x) Γ, x : τ 1 e : τ 2 Γ λx. e : τ 1 τ 2 Γ e 1 : τ 2 τ 1 Γ e 2 : τ 2 Γ e 1 e 2 : τ 1 The function-introduction rule is the interesting one... Dan Grossman CS-XXX 2012, Lecture 9 15

24 A closer look Where did τ 1 come from? Γ, x : τ 1 e : τ 2 Γ λx. e : τ 1 τ 2 Our rule inferred or guessed it To be syntax directed, change λx. e to λx : τ. e and use that τ Can think of adding x as shadowing or requiring x Dom(Γ) Systematic renaming (α-conversion) ensures x Dom(Γ) is not a problem Dan Grossman CS-XXX 2012, Lecture 9 16

25 A closer look Γ, x : τ 1 e : τ 2 Γ λx. e : τ 1 τ 2 Is our type system too restrictive? That s a matter of opinion But it does reject programs that don t get stuck Example: (λx. (x (λy. y)) (x 3)) λz. z Does not get stuck: Evaluates to 3 Does not type-check: There is no τ1, τ 2 such that x : τ 1 (x (λy. y)) (x 3) : τ 2 because you have to pick one type for x Dan Grossman CS-XXX 2012, Lecture 9 17

26 Always restrictive Whether or not a program gets stuck is undecidable: If e has no constants or free variables, then e (3 4) or e x gets stuck if and only if e terminates (cf. the halting problem) Old conclusion: Strong types for weak minds Need a back door (unchecked casts) Modern conclusion: Unsafe constructs almost never worth the risk Make false positives (rejecting safe program) rare enough Have compile-time resources for fancy type systems Make workarounds for false positives convenient enough Dan Grossman CS-XXX 2012, Lecture 9 18

27 How does STLC measure up? So far, STLC is sound: As language dictators, we decided c v and undefined variables were bad meaning neither values nor reducible Our type system is a conservative checker that an expression will never get stuck But STLC is far too restrictive: In practice, just too often that it prevents safe and natural code reuse More fundamentally, it s not even Turing-complete Turns out all (well-typed) programs terminate A good-to-know and useful property, but inappropriate for a general-purpose PL That s okay: We will add more constructs and typing rules Dan Grossman CS-XXX 2012, Lecture 9 19

28 Type Soundness We will take a syntactic (operational) approach to soundness/safety The popular way since the early 1990s Theorem (Type Safety): If e : τ then e diverges or e n v for an n and v such that v : τ That is, if e : τ, then e cannot get stuck Proof: Next lecture Dan Grossman CS-XXX 2012, Lecture 9 20

### CSE 505: Programming Languages. Lecture 10 Types. Zach Tatlock Winter 2015

CSE 505: Programming Languages Lecture 10 Types Zach Tatlock Winter 2015 What Are We Doing? Covered a lot of ground! Easy to lose sight of the big picture. Zach Tatlock CSE 505 Winter 2015, Lecture 10

### CS152: 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

### CSE 505: Concepts of Programming Languages

CSE 505: Concepts of Programming Languages Dan Grossman Fall 2003 Lecture 6 Lambda Calculus Dan Grossman CSE505 Fall 2003, Lecture 6 1 Where we are Done: Modeling mutation and local control-flow Proving

### Whereweare. 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

### Review. 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]:

### CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011

CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:

### CS-XXX: Graduate Programming Languages. Lecture 17 Recursive Types. Dan Grossman 2012

CS-XXX: Graduate Programming Languages Lecture 17 Recursive Types Dan Grossman 2012 Where are we System F gave us type abstraction code reuse strong abstractions different from real languages (like ML),

### Goal. 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

### 1 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,

### Tradeoffs. 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

### CSE505, 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

### Simply-Typed Lambda Calculus

#1 Simply-Typed Lambda Calculus #2 Back to School What is operational semantics? When would you use contextual (small-step) semantics? What is denotational semantics? What is axiomatic semantics? What

### Programming 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

### CS 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

### CSE-505: Programming Languages. Lecture 20.5 Recursive Types. Zach Tatlock 2016

CSE-505: Programming Languages Lecture 20.5 Recursive Types Zach Tatlock 2016 Where are we System F gave us type abstraction code reuse strong abstractions different from real languages (like ML), but

### COS 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

### CMSC 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.......................

### Programming 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

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

CSE 505, Fall 2008, Final Examination 11 December 2008 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

### CSCI-GA Scripting Languages

CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

### More Lambda Calculus and Intro to Type Systems

More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic

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

CSE 505, Fall 2008, Midterm Examination 29 October 2008 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

### CS558 Programming Languages

CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

### Types 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

### Harvard 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

### CIS 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

### COMP 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

### CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012

CS-XXX: Graduate Programming Languages Lecture 22 Class-Based Object-Oriented Programming Dan Grossman 2012 PL Issues for OOP? OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive

### CSE 505: Concepts of Programming Languages

CSE 505: Concepts of Programming Languages Dan Grossman Fall 2009 Lecture 4 Proofs about Operational Semantics; Pseudo-Denotational Semantics Dan Grossman CSE505 Fall 2009, Lecture 4 1 This lecture Continue

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, April 3, 2014 1 Error-propagating semantics For the last few weeks, we have been studying type systems.

### CS152: Programming Languages. Lecture 24 Bounded Polymorphism; Classless OOP. Dan Grossman Spring 2011

CS152: Programming Languages Lecture 24 Bounded Polymorphism; Classless OOP Dan Grossman Spring 2011 Revenge of Type Variables Sorted lists in ML (partial): type a slist make : ( a -> a -> int) -> a slist

### Programming 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

### CMSC 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

### Dependent types and program equivalence. Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg

Dependent types and program equivalence Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg What are dependent types? Types that depend on values of other types

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

CSE 505, Fall 2008, Final Examination 11 December 2008 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

### Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free

### Lecture 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,

### CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011

CS152: Programming Languages Lecture 23 Advanced Concepts in Object-Oriented Programming Dan Grossman Spring 2011 So far... The difference between OOP and records of functions with shared private state

### Type Systems, Type Inference, and Polymorphism

6 Type Systems, Type Inference, and Polymorphism Programming involves a wide range of computational constructs, such as data structures, functions, objects, communication channels, and threads of control.

### Harvard 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

### COMP 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

### We defined congruence rules that determine the order of evaluation, using the following evaluation

CS 4110 Programming Languages and Logics Lectures #21: Advanced Types 1 Overview In this lecture we will extend the simply-typed λ-calculus with several features we saw earlier in the course, including

### Dependent types and program equivalence. Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg

Dependent types and program equivalence Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg Doing dependent types wrong without going wrong Stephanie Weirich,

### Lecture 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

### Fundamentals and lambda calculus

Fundamentals and lambda calculus Again: JavaScript functions JavaScript functions are first-class Syntax is a bit ugly/terse when you want to use functions as values; recall block scoping: (function ()

### More Lambda Calculus and Intro to Type Systems

#1 More Lambda Calculus and Intro to Type Systems #2 Plan Heavy Class Participation Thus, wake up! (not actually kidding) Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems

### Gradual Typing for Functional Languages. Jeremy Siek and Walid Taha (presented by Lindsey Kuper)

Gradual Typing for Functional Languages Jeremy Siek and Walid Taha (presented by Lindsey Kuper) 1 Introduction 2 What we want Static and dynamic typing: both are useful! (If you re here, I assume you agree.)

### CSE341: Programming Languages Lecture 11 Type Inference. Dan Grossman Spring 2016

CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Spring 2016 Type-checking (Static) type-checking can reject a program before it runs to prevent the possibility of some errors A feature

### Compilers and computer architecture: Semantic analysis

1 / 1 Compilers and computer architecture: Semantic analysis Martin Berger Alex Jeffery October 2018 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 24 Thursday, April 19, 2018 1 Error-propagating semantics For the last few weeks, we have been studying type systems.

### CS 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

### Lambda Calculus. Variables and Functions. cs3723 1

Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can

### Introduction to Lambda Calculus. Lecture 7 CS /08/09

Introduction to Lambda Calculus Lecture 7 CS 565 02/08/09 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)

### CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012

CS-XXX: Graduate Programming Languages Lecture 23 Types for OOP; Static Overloading and Multimethods Dan Grossman 2012 So far... Last lecture (among other things): The difference between OOP and records

### CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

### COMP 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 Lambda Calculus and Intro to Type Systems

More Lambda Calculus and Intro to Type Systems #1 One Slide Summary The lambda calculus is a model of computation or a programming language that is as expressive as a Turing machine. The lambda calculus

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

Fundamentals and lambda calculus Deian Stefan (adopted from my & Edward Yang s CSE242 slides) Logistics Assignments: Programming assignment 1 is out Homework 1 will be released tomorrow night Podcasting:

### Concepts 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.

### Lecture Notes on Program Equivalence

Lecture Notes on Program Equivalence 15-312: Foundations of Programming Languages Frank Pfenning Lecture 24 November 30, 2004 When are two programs equal? Without much reflection one might say that two

### CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013

CSE341: Programming Languages Lecture 9 Function-Closure Idioms Dan Grossman Winter 2013 More idioms We know the rule for lexical scope and function closures Now what is it good for A partial but wide-ranging

### Lecture 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

### - 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

### Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)

### Featherweight 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

### Don t Believe the Hype. CS152: Programming Languages. Lecture 21 Object-Oriented Programming. Class-based OOP. So what is OOP?

Don t Believe the Hype CS152: Programming Languages Lecture 21 Object-Oriented Programming Dan Grossman Spring 2011 OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive analogy

### Types and Type Inference

CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of

### Lecture 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

### Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics

### CMSC 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

### Lambda 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

### Type 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

### Functional Programming

Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming

### Programming 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

### Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.

### λ 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

### Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

### Programming Languages (PL)

1 2 3 4 5 6 7 8 9 10 11 Programming Languages (PL) Programming languages are the medium through which programmers precisely describe concepts, formulate algorithms, and reason about solutions. In the course

### Types and Type Inference

Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion

### CSE 505, Fall 2007, Final Examination 10 December Please do not turn the page until everyone is ready.

CSE 505, Fall 2007, Final Examination 10 December 2007 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

### CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

### CMSC 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!

### Recursive 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

### CS558 Programming Languages

CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And

### CS558 Programming Languages

CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

### Variables. Substitution

Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

### CS 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,

### Introduction to the Lambda Calculus

Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et

### Costly 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

### Denotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Denotational Semantics; Lambda Calculus Basics Week 4: Tue Feb 13 Fri Feb 16, 2018 1 Denotational Semantics (a) Give the

### Announcements. Working on requirements this week Work on design, implementation. Types. Lecture 17 CS 169. Outline. Java Types

Announcements Types Working on requirements this week Work on design, implementation Lecture 17 CS 169 Prof. Brewer CS 169 Lecture 16 1 Prof. Brewer CS 169 Lecture 16 2 Outline Type concepts Where do types

### CS4215 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

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Summer 2017 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!

### CMSC 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

### Part VI. Imperative Functional Programming

Part VI Imperative Functional Programming Chapter 14 Mutable Storage MinML is said to be a pure language because the execution model consists entirely of evaluating an expression for its value. ML is

### Supplementary Notes on Exceptions

Supplementary Notes on Exceptions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 9 September 25, 2002 In this lecture we first give an implementation of the C-machine for the fragment

### Typical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated

Typical workflow concrete synta (string) "(fn => + ) 4" Parsing CSE341: Programming Languages abstract synta (tree) Lecture 17 Implementing Languages Including Closures Function Constant + 4 Var Var Type

### Recursive 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