Simply Typed Lambda Calculus

Size: px
Start display at page:

Download "Simply Typed Lambda Calculus"

Transcription

1 Simply Typed Lambda Calculus

2 Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::= true false x : T.t Types T ::= Bool T! T

3 Evaluation Rules t 1! t 0 1 t 1 t 2! t 0 1 t 2 t 2! t 0 2 v 1 t 2! v 1 t 0 2 E-App1 E-App2 ( x : T.t 12 ) v 2! [x 7! v 2 ]t 12 E-AppAbs if true t 2 t 3! t 2 if false t 2 t 3! t 3 E-IfTrue E-IfFalse t 1! t 0 1 if t 1 t 2 t 3! if t 0 1 t 2 t 3 E-If

4 Normal form When does the evaluation terminate? It terminates when no rules apply to it if true (if true false false) false! if true false false! false 6! if true (if x.false false false ) false! if x.false false false 6! A term t is in normal form if no evaluation rule applies to it Is every value in normal form? Is every normal form a value?

5 Stuck Terms in normal form but not a value Runtime errors situations where the operational semantics does not know what to know machine failures (segmentation faults, execution of illegal instructions, etc)

6 Static Type System Verify that given terms will not get stuck Without actually evaluating the term. By checking that the term is well-typed We can prove that well-typed terms do go wrong However, not all ill-typed terms get stuck

7 Static Type System Defined by type inference rules Intuition x + y + 1 ` t : T Γ Id fin Type if evaluating t terminates, the final result has T type

8 Inference Rules (Typing rules) (x) =T ` x : T T-Var [x 7! T 1 ] ` t 2 : T 2 ` x : T 1.t 2 : T 1! T 2 T-Abs ` t 1 : T 11! T 12 ` t 2 : T 11 ` t 1 t 2 : T 12 T-App ` true : Bool ` false : Bool T-True T-False ` t 1 : Bool ` t 2 : T ` t 3 : T ` if t 1 t 2 t 3 : T T-If

9 Examples well-typed term ` [x 7! Bool](x) =Bool T-Var [x 7! Bool] ` x : Bool T-Abs x : Bool.x : Bool! Bool ` true : Bool ` ( x : Bool.x) true : Bool T-True T-App ill-typed term [x 7! Bool] ` x : Bool! x : Bool.x : Bool! Bool ` true : Bool ` false : Bool ` if x : Bool.x then true else false :

10 The type system is incomplete Terms that do not have types may not go well

11 The type system is safe (sound) If type checking succeeds, terms never go wrong

12 Safety = Progress + Preservation progress: a well-typed term is not stuck (either it is a value or it can take a step according to the evaluation rules) preservation: if a well-typed term takes a step of evaluation, then the resulting term is also well-typed

13 Safety = Progress + Preservation ` Lemma 1 (Progress). Suppose t is a closed term. If t is well-typed (i.e., ` t : T for some T ), then either t is a value or there is some t 0 with t! t 0 : ` t : T =) t is a value or 9t 0.t! t 0 Lemma 2 (Preservation). If ` t : T and t! t 0, then ` t 0 : T. Theorem 1 (Type Safety). Suppose t is a closed term. If ` t : T, then t does not get stuck during evaluation. Furthermore, if t reaches a value v, then v is of the T type. Proof. By the Progress and Preservation Lemmas. ut

14 Proofs

15 Type Checking Algorithm Easy, thanks to the type annotations TC(,x)= TC :(Id! Type) t! Type (x) TC(, x : T 1.t 2 )=lett 2 = TC( [x 7! T 1 ],t 2 ) in T 1! T 2 TC(,t 1 t 2 )=lett 1 = TC(,t 1 ) let T 2 = TC(,t 2 ) in if T 1 = T 11! T 12 and T 11 = T 2 then T 12 else Error TC(, true) =Bool TC(, false) =Bool TC(, if t 1 t 2 t 3 )=iftc(,t 1 )=Bool and TC(, t 2 )=TC(, t 3 ) then TC(,t 2 ) else Error

16 Simply Typed Lambda Calculus (ver2) Lambda calculus without type annotations Language values: types: t ::= x variable x.t abstraction tt application true false boolean values if ttt conditional expression v ::= true false x.t T ::= Bool T! T

17 Evaluation rules! t 1! t 0 1 t 1 t 2! t 0 1 t 2 t 2! t 0 2 v 1 t 2! v 1 t 0 2 E-App1 E-App2 ( x.t 12 ) v 2! [x 7! v 2 ]t 12 E-AppAbs if true t 2 t 3! t 2 if false t 2 t 3! t 3 E-IfTrue E-IfFalse t 1! t 0 1 if t 1 t 2 t 3! if t 0 1 t 2 t 3 E-If

18 Typing rules (sound) (x) =T ` x : T T-Var [x 7! T 1 ] ` t : T 2 ` x.t : T 1! T 2 T-Abs ` t 1 : T 11! T 12 ` t 2 : T 11 ` t 1 t 2 : T 12 T-App ` true : Bool ` false : Bool T-True T-False ` t 1 : Bool ` t 2 : T ` t 3 : T ` if t 1 t 2 t 3 : T T-If

19 Implementation is not easy (x) =T ` x : T T-Var [x 7! T 1 ] ` t : T 2 ` x.t : T 1! T 2 T-Abs ` t 1 : T 11! T 12 ` t 2 : T 11 ` t 1 t 2 : T 12 T-App ` true : Bool ` false : Bool T-True T-False ` t 1 : Bool ` t 2 : T ` t 3 : T ` if t 1 t 2 t 3 : T T-If

20 Two s Type annotations x : T.t used in languages like C, C++, Java, etc helpful for design and documentation but tedious Automatic type inference used in languages like ML, Haskell, Scala, etc compiler figure out the types of expressions

21 Quiz)Type Inference ( x.x) 1 ( x.x 1) x. y.x

22 Automatic Type Inference Figure out types of expressions by observing how they are used For a carefully designed language, compiler can always infer the types of any expression! Two steps setup: While scanning the program, generate a system of equations between unknown types solving: Unification algorithm

23 Example 1: ( x.x) 1 1. setup 1-1. Put labels on every sub-expression of the program ( x. x ) 1 {z} {z}

24 Example 1: ( x.x) 1 1. setup 1-2. For each expression and bound variable, generate unknowns that denote the types of them {z} {z} ( x. x ) 1 {z} {z} , 2, 3, 4, x

25 Example 1: ( x.x) 1 1. setup 1-3. Based on the type rules, generate equations that must hold between the unknowns ex) What equation does the T-Abs rule dictate? ` {z} {z} [x 7! T 1 ] ` t : T 2 ` x.t : T 1! T 2 T-Abs x.t = x! t `! ` ex) What equation does the T-App rule dictate? `!! ` t 1 : T 11! T 12 ` t 2 : T 11 ` t 1 t 2 : T 12 T-App t1 = t2! (t1 t 2 )

26 Example 1: ( x.x) 1 1. setup 1-3. Based on the type rules, generate equations that must hold between the unknowns ( x. x ) 1 {z} {z} 1 2 {z} 3 4 {z} 2 = x! 1 2 = 3! 4 3 = int 1 = x 1, 2, 3, 4, x

27 Example 1: ( x.x) 1 2. solving Find a solution that satisfies all equations. (s expressed by substitutions) equation 2 = x! 1 2 = 3! 4 3 = int 1 = x solution 1 7! int 2 7! int! int 3 7! int 4 7! int x 7! int

28 Example 1: ( x.x) 1 2. solving Initially, all of the equations are to be solved and the substitution(solution) is empty. 2 = x! 1 2 = 3! 4 3 = int 1 = x! Consider 2 = x! 1 true. We add it Generate substitution 2 7! x! 1

29 Example 1: ( x.x) 1 Move it to the solution (with update): 2 = 3! 4 3 = int 1 = x 2 7! x! 1 Update equation:! x! 1 = 3! 4 3 = int 1 = x 2 7! x! 1

30 Example 1: ( x.x) 1! Consider x! 1 = 3! 4 3 = int 1 = x 2 7! x! 1 Generate substitution x! 1 = 3! 4.! x! x 7! 3 and 1 7! 4. 3 = int 2 7! 3! 4 1 = x 7! 3 x 1 7! 4

31 Example 1: ( x.x) 1 Update equation: Next, 3 = int 2 7! 3! 4 4 = x 7! ! 4 7! 7! 4 = int 2 7! int! 4 x 7! int 1 7! 4 3 7! int

32 Example 1: ( x.x) 1 7! 4 = int 2 7! int! 4 x 7! int 1 7! 4 3 7! int Finally, 2 7! int! int x 7! int 1 7! int 3 7! int 4 7! int

33 Inferred type ( x. x ) 1 {z} {z} ! int 2 7! int! int 3 7! int 4 7! int x 7! int

34 Example 2: x.(x 1) 1. setup 1-1. Put labels on every sub-expression of the program {z} {z x. ( x {z} 1 1 ) {z} 0 2 {z } 3

35 Example 2: x.(x 1) 1. setup x. ( x {z} 1 1 ) {z} 0 2 {z } 3 {z} {z {z} {z} 3 = x! 2 1 = int! 2 x = 1

36 Example 2: x.(x 1) 1. solving {z} {z 3 = x! 2 1 = int! 2 x = 1 1 = int! 2 x = 1 3 7! x! 2

37 Example 2: x.(x 1) 1. solving {z} {z x = int! 2 3 7! x! 2 1 7! int! 2! 7!! 3 7! (int! 2 )! 2 1 7! int! 2 x 7! int! 2

38 Inferred type x. ( x {z} 1 1 ) {z} 0 2 {z } 3 3 7! (int! 2 )! 2 1 7! int! 2 x 7! int! 2! The types are polymorphic in 2

39 Example 3: if x then x 1 else 0 {z 0 = bool if x {z} 0 then x 1 1 else 0 {z} = 2 3 = 1 2 = int 1 = int x = int

40 Example 3: if x then x 1 else 0 0 = bool 1 = 2 3 = 1 2 = int 1 = int x = int x = 0 1 = 2 3 = 1 2 = int 1 = int x = int x = bool 0 7! bool

41 Example 3: if x then x 1 else 0 3 = 2 2 = int 1 = int x = int x = bool 2 = int 1 = int x = int x = bool 1 7! 2 0 7! bool 3 7! 2 1 7! 2 0 7! bool

42 Example 3: if x then x 1 else 0 7! 1 = int x = int x = bool x = int x = bool 2 7! int 3 7! int 1 7! int 0 7! bool 2 7! int 3 7! int 1 7! int 0 7! bool

43 Example 3: if x then x 1 else 0 7! 7! int = bool 2 7! int 3 7! int 1 7! int 0 7! bool x 7! int

44 Example 4: x.(x x) {z} {z} {z} {z x. ( x {z} 1 x ) {z} 2 3 {z } 4 x = 1 x = 2 4 = x! 3 1 = 2! 3

45 Example 4: x.(x x) x = 1 x = 2 4 = x! 3 1 = 2! 3 {z} {z 1 = 2 4 = 1! 3 1 = 2! 3 x 7! 1

46 Example 4: x.(x x)! {z} {z 4 = 2! 3 2 = 2! 3 1 7! 2 x 7! 1

47 Example 4: x.(x x)! 7! {z} {z 2 = 2! 3 4 7! 2! 3 1 7! 2 x 7! 1 Occurrence check: check if, in an equation of form α = T, the type variable α occurs in the type T

Typed Arithmetic Expressions

Typed Arithmetic Expressions Typed Arithmetic Expressions CS 550 Programming Languages Jeremy Johnson TAPL Chapters 3 and 5 1 Types and Safety Evaluation rules provide operational semantics for programming languages. The rules provide

More information

CIS 500 Software Foundations Midterm II Answer key November 17, 2004

CIS 500 Software Foundations Midterm II Answer key November 17, 2004 CIS 500 Software Foundations Midterm II Answer key November 17, 2004 Simply typed lambda-calculus The following questions refer to the simply typed lambda-calculus with booleans and error. The syntax,

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg Type Inference For the Simply-Typed Lambda Calculus Albert-Ludwigs-Universität Freiburg Peter Thiemann, Manuel Geffken University of Freiburg 24. Januar 2013 Outline 1 Introduction 2 Applied Lambda Calculus

More information

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus Course 2D1453, 200607 Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Typing λterms The uptyped λcalculus

More information

Lecture Notes: Program Analysis Correctness

Lecture Notes: Program Analysis Correctness Lecture Notes: Program Analysis Correctness 15-819O: Program Analysis Jonathan Aldrich jonathan.aldrich@cs.cmu.edu Lecture 5 1 Termination As we think about the correctness of program analysis, let us

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 11: Subtyping Prof Liang Huang huang@qccscunyedu Big Picture Part I: Fundamentals Functional Programming and Basic Haskell Proof by Induction and Structural Induction

More information

Lectures Notes on Progress

Lectures Notes on Progress Lectures Notes on Progress 15-312: Foundations of Programming Languages Frank Pfenning Lecture 7 September 21, 2004 In this lecture we prove the progress property for MinML, discuss type safety, and consider

More information

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics Dynamic Semantics Operational Semantics Denotational Semantic Dynamic Semantics Operational Semantics Operational Semantics Describe meaning by executing program on machine Machine can be actual or simulated

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Subtyping Motivation With our usual typing rule for applications the term is not well typed. ` t 1 : T 11!T 12 ` t

More information

Recitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages

Recitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages Recitation 2: Binding, Semantics, and Safety 15-312: Foundations of Programming Languages Charles Yuan, Jeanne Luning Prak September 5, 2018 1 Abstract Binding Trees The abstract syntax trees we saw previously

More information

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008 CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008 Contents 1 Polymorphism 1 2 Polymorphic λ-calculus: Syntax 1 3 Static Semantics 2 4 Dynamic Semantics

More information

Limitations of OCAML records

Limitations of OCAML records Limitations of OCAML records The record types must be declared before they are used; a label e can belong to only one record type (otherwise fun x x.e) would have several incompatible types; we cannot

More information

Axiomatic Semantics. Operational semantics. Good for. Not good for automatic reasoning about programs

Axiomatic Semantics. Operational semantics. Good for. Not good for automatic reasoning about programs Review Operational semantics relatively l simple many flavors (small vs. big) not compositional (rule for while) Good for describing language implementation reasoning about properties of the language eg.

More information

A Polymorphic Type and System for Multi-Staged Exceptions

A Polymorphic Type and System for Multi-Staged Exceptions A Polymorphic Type System for Multi-Staged Exceptions Seoul National University 08/04/2006 This is a joint work with In-Sook Kim and Kwangkeun Yi Outlie 1. Introduction and Examples 2. Operational Semantics

More information

Reasoning About Imperative Programs. COS 441 Slides 10b

Reasoning About Imperative Programs. COS 441 Slides 10b Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program

More information

An Introduction to Logical Relations Proving Program Properties Using Logical Relations

An Introduction to Logical Relations Proving Program Properties Using Logical Relations An Introduction to Logical Relations Proving Program Properties Using Logical Relations Lau Skorstengaard lask@cs.au.dk July 27, 2018 Contents 1 Introduction 2 1.1 Simply Typed Lambda Calculus....................

More information

CMSC 631 Program Analysis and Understanding Fall Type Systems

CMSC 631 Program Analysis and Understanding Fall Type Systems Program Analysis and Understanding Fall 2017 Type Systems Type Systems A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according

More information

CIS 500 Software Foundations Final Exam Answer key December 20, 2004

CIS 500 Software Foundations Final Exam Answer key December 20, 2004 CIS 500 Software Foundations Final Exam Answer key December 20, 2004 True/False questions For each of the following statements, circle T if the sentence is true or F otherwise. 1. (10 points) (a) T F The

More information

Lecture 2: Axiomatic semantics

Lecture 2: Axiomatic semantics Chair of Software Engineering Trusted Components Prof. Dr. Bertrand Meyer Lecture 2: Axiomatic semantics Reading assignment for next week Ariane paper and response (see course page) Axiomatic semantics

More information

Axiomatic Semantics. Lecture 9 CS 565 2/12/08

Axiomatic Semantics. Lecture 9 CS 565 2/12/08 Axiomatic Semantics Lecture 9 CS 565 2/12/08 Axiomatic Semantics Operational semantics describes the meaning of programs in terms of the execution steps taken by an abstract machine Denotational semantics

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

Programming Languages

Programming Languages CSE 230: Winter 2010 Principles of Programming Languages Lecture 10: Programming in λ-calculusc l l Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2

More information

Denotational Semantics of Programs. : SimpleExp N.

Denotational Semantics of Programs. : SimpleExp N. Models of Computation, 2010 1 Denotational Semantics of Programs Denotational Semantics of SimpleExp We will define the denotational semantics of simple expressions using a function : SimpleExp N. Denotational

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Sasa Misailovic 4110 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421a Based in part on slides by Mattox Beckman, as updated by Vikram Adve, Gul

More information

Hoare Logic: Reasoning About Imperative Programs

Hoare Logic: Reasoning About Imperative Programs Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Programming Paradigms Functional. (Haskell, SML, OCaml,... ) main paradigm:

More information

Applying Predicate Logic to Monitoring Network Traffic

Applying Predicate Logic to Monitoring Network Traffic Applying Predicate Logic to Monitoring Network Traffic Wolfgang Schreiner Wolfgang.Schreiner@risc.jku.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria http://www.risc.jku.at

More information

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Notes from Yesterday s  Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons. CIS 500 Software Foundations Fall 2006 Notes from Yesterday s Email Discussion November 1 Some lessons This is generally a crunch-time in the semester Slow down a little and give people a chance to catch

More information

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready.

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

More information

M ::= x M M x = M M :: M x :: x

M ::= x M M x = M M :: M x :: x Mini-ML expressions M ::= x variable true boolean values false if M then M else M conditional lx (M) function abstraction MM function application let x = M in M local declaration nil nil list M :: M list

More information

Simple Type Extensions

Simple Type Extensions Simple Type Extensions Type Systems, Lecture 4 Jevgeni Kabanov Tartu, 14.02.2006 PREVIOUSLY ON TYPE SYSTEMS Lambda Calculus Embedded Booleans and Arithmetical expressions Fixpoints and Recursion Simple

More information

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007 CSE 230: Winter 2007 Principles of Programming Languages Lecture 12: The λ-calculus Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2 Several evaluation

More information

September 14. Fall Software Foundations CIS 500

September 14. Fall Software Foundations CIS 500 CIS 500 Software Foundations Fall 2005 September 14 CIS 500, September 14 1 Announcements I will be away September 19-October 5. I will be reachable by email. Fastest response cis500@cis.upenn.edu No office

More information

Information Flow Inference for ML

Information Flow Inference for ML Information Flow Inference for ML Vincent Simonet INRIA Rocquencourt Projet Cristal MIMOSA September 27, 2001 Information flow account number bank applet order vendor account H order L bank H vendor L

More information

Extending the Lambda Calculus: An Eager Functional Language

Extending the Lambda Calculus: An Eager Functional Language Syntax of the basic constructs: Extending the Lambda Calculus: An Eager Functional Language canonical forms z cfm ::= intcfm boolcfm funcfm tuplecfm altcfm intcfm ::= 0 1-1... boolcfm ::= boolconst funcfm

More information

Operational Semantics

Operational Semantics Operational Semantics Semantics and applications to verification Xavier Rival École Normale Supérieure Xavier Rival Operational Semantics 1 / 50 Program of this first lecture Operational semantics Mathematical

More information

Interoperation for Lazy and Eager Evaluation

Interoperation for Lazy and Eager Evaluation Interoperation for Lazy and Eager Evaluation 1 Matthews & Findler New method of interoperation Type safety, observational equivalence & transparency Eager evaluation strategies Lazy vs. eager 2 Lambda

More information

CSE505, Fall 2012, Final Examination December 10, 2012

CSE505, Fall 2012, Final Examination December 10, 2012 CSE505, Fall 2012, Final Examination December 10, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at 12:20. You can rip apart

More information

COP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen

COP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen Assertions and Preconditions Assertions are used by programmers to verify run-time execution An assertion is a

More information

Information Flow Inference for ML

Information Flow Inference for ML POPL 02 INRIA Rocquencourt Projet Cristal Francois.Pottier@inria.fr http://cristal.inria.fr/~fpottier/ Vincent.Simonet@inria.fr http://cristal.inria.fr/~simonet/ Information flow analysis account number

More information

Type Soundness for Path Polymorphism

Type Soundness for Path Polymorphism Type Soundness for Path Polymorphism Andrés Ezequiel Viso 1,2 joint work with Eduardo Bonelli 1,3 and Mauricio Ayala-Rincón 4 1 CONICET, Argentina 2 Departamento de Computación, FCEyN, UBA, Argentina 3

More information

1. Object Calculus. Object calculus is to OO languages what lambda calculus is to functional languages

1. Object Calculus. Object calculus is to OO languages what lambda calculus is to functional languages 1. Object Calculus In this section we will introduce a calculus of objects that gives a simple but powerful mathematical model to study object based languages. Object calculus is to OO languages what lambda

More information

PLC type system. if (x : t) 2 G. G ` x : t. G, x : t 1 ` M : t 2 G ` lx : t 1 (M) : t 1 t 2. if x /2 dom(g)

PLC type system. if (x : t) 2 G. G ` x : t. G, x : t 1 ` M : t 2 G ` lx : t 1 (M) : t 1 t 2. if x /2 dom(g) PLC type system (var) G ` x : t if (x : t) 2 G (fn) G, x : t 1 ` M : t 2 G ` lx : t 1 (M) : t 1 t 2 if x /2 dom(g) (app) G ` M : t 1 t 2 G ` M 0 : t 1 G ` MM 0 : t 2 (gen) G ` M : t G ` La (M) : 8a (t)

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Where we re going Type Systems... Type systems are one of the most fascinating and powerful aspects of programming

More information

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready. CSE 505, Fall 2005, Midterm Examination 8 November 2005 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.

More information

Chapter 5. Finite Automata

Chapter 5. Finite Automata Chapter 5 Finite Automata 5.1 Finite State Automata Capable of recognizing numerous symbol patterns, the class of regular languages Suitable for pattern-recognition type applications, such as the lexical

More information

Proof Calculus for Partial Correctness

Proof Calculus for Partial Correctness Proof Calculus for Partial Correctness Bow-Yaw Wang Institute of Information Science Academia Sinica, Taiwan September 7, 2016 Bow-Yaw Wang (Academia Sinica) Proof Calculus for Partial Correctness September

More information

CIS 500 Software Foundations Final Exam. Answer key. December 20, 2006

CIS 500 Software Foundations Final Exam. Answer key. December 20, 2006 CIS 500 Software Foundations Final Exam Answer key December 20, 2006 Instructions This is a closed-book exam. You have 120 minutes to answer all of the questions. The entire exam is worth 120 points. Questions

More information

Dynamic Dependency Monitoring to Secure Information Flow

Dynamic Dependency Monitoring to Secure Information Flow Dynamic Dependency Monitoring to Secure Information Flow Paritosh Shroff Scott F. Smith Mark Thober Department of Computer Science Johns Hopkins University {pari,scott,mthober}@cs.jhu.edu Abstract Although

More information

Property Checking of Safety- Critical Systems Mathematical Foundations and Concrete Algorithms

Property Checking of Safety- Critical Systems Mathematical Foundations and Concrete Algorithms Property Checking of Safety- Critical Systems Mathematical Foundations and Concrete Algorithms Wen-ling Huang and Jan Peleska University of Bremen {huang,jp}@cs.uni-bremen.de MBT-Paradigm Model Is a partial

More information

Quantum Functional Programming Language & Its Denotational Semantics

Quantum Functional Programming Language & Its Denotational Semantics Quantum Functional Programming Language & Its Denotational Semantics Ichiro Hasuo Dept. Computer Science University of Tokyo Naohiko Hoshino Research Inst. for Math. Sci. Kyoto University Talk based on:

More information

Software Engineering

Software Engineering Software Engineering Lecture 07: Design by Contract Peter Thiemann University of Freiburg, Germany 02.06.2014 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

arxiv: v3 [cs.pl] 15 May 2011

arxiv: v3 [cs.pl] 15 May 2011 A Step-indexed Semantic Model of Types for the Call-by-Name Lambda Calculus arxiv:1105.1985v3 [cs.pl] 15 May 2011 Abstract Step-indexed semantic models of types were proposed as an alternative to purely

More information

CIS 500 Software Foundations Final Exam Answer key December 14, 2005

CIS 500 Software Foundations Final Exam Answer key December 14, 2005 CIS 500 Software Foundations Final Exam Answer key December 14, 2005 True/False questions For each of the following statements, circle T if the sentence is true or F otherwise. 1. (9 points) (a) T F The

More information

Gradual Union Types. Complete Definition and Proofs. Technical Report TR/DCC University of Chile June Matías Toro and Éric Tanter

Gradual Union Types. Complete Definition and Proofs. Technical Report TR/DCC University of Chile June Matías Toro and Éric Tanter Gradual Union Types Complete Definition and Proofs Technical Report TR/DCC-07- University of Chile June 07 Matías Toro and Éric Tanter PLEIAD Laboratory Computer Science Department (DCC) University of

More information

Theories of Programming Languages Assignment 5

Theories of Programming Languages Assignment 5 Theories of Programming Languages Assignment 5 December 17, 2012 1. Lambda-Calculus (see Fig. 1 for initions of = β, normal order evaluation and eager evaluation). (a) Let Ω = ((λx. x x) (λx. x x)), and

More information

Principles of Program Analysis: Control Flow Analysis

Principles of Program Analysis: Control Flow Analysis Principles of Program Analysis: Control Flow Analysis Transparencies based on Chapter 3 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis. Springer Verlag

More information

CIS 500 Software Foundations Fall October. Review. Administrivia. Subtyping

CIS 500 Software Foundations Fall October. Review. Administrivia. Subtyping CIS 500 Software Foundations Fall 2002 Administrivia Prof. Pierce out of town Nov. 5 14 No office hours Nov 5, 7, 12, or 14 Next Wednesday: guest lecturer (on Chapter 16) Following Monday: review session

More information

Introduction to lambda calculus Part 2

Introduction to lambda calculus Part 2 Introduction to lambda calculus Part 2 Antti-Juhani Kaijanaho 2017-01-24... 1 Untyped lambda calculus 1.1 Syntax... x, y, z Var t, u Term t, u ::= x t u λx t... In this document, I will be using the following

More information

Mechanics of Static Analysis

Mechanics of Static Analysis Escuela 03 III / 1 Mechanics of Static Analysis David Schmidt Kansas State University www.cis.ksu.edu/~schmidt Escuela 03 III / 2 Outline 1. Small-step semantics: trace generation 2. State generation and

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

Quantum Effects. Juliana K. Vizzotto 1 Thorsten Altenkirch 2. Amr Sabry January Yale CS Colloquium Page 1

Quantum Effects. Juliana K. Vizzotto 1 Thorsten Altenkirch 2. Amr Sabry January Yale CS Colloquium Page 1 Quantum Effects Juliana K. Vizzotto 1 Thorsten Altenkirch 2 Amr Sabry 3 1 Federal University of Rio Grande do Sul 2 The University of Nottingham 3 Indiana University 2 January 25 Yale CS Colloquium Page

More information

Normalization by Evaluation

Normalization by Evaluation Normalization by Evaluation Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University PhD Seminar in Mathematical Engineering EAFIT University, Medellin, Colombia 9

More information

Element x is R-minimal in X if y X. R(y, x).

Element x is R-minimal in X if y X. R(y, x). CMSC 22100/32100: Programming Languages Final Exam M. Blume December 11, 2008 1. (Well-founded sets and induction principles) (a) State the mathematical induction principle and justify it informally. 1

More information

Certification of Safe Polynomial Memory Bounds (Extended Version)

Certification of Safe Polynomial Memory Bounds (Extended Version) Certification of Safe Polynomial Memory Bounds (Extended Version) Javier de Dios and Ricardo Peña Departamento de Sistemas Informáticos y Computación Universidad Complutense de Madrid, Spain jdcastro@aventia.com,

More information

Principles of Program Analysis: A Sampler of Approaches

Principles of Program Analysis: A Sampler of Approaches Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis Springer Verlag

More information

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 P. 1 of 7 THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 December, 2014 Time: 2 hrs. Instructions The exam contains questions totaling 100 points. Answer all questions.

More information

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 7 November 29 November 29, 2006 - version 1.0 Plan PREVIOUSLY: 1. type safety as progress and preservation 2. typed arithmetic expressions 3. simply typed lambda

More information

Coinductive big-step operational semantics

Coinductive big-step operational semantics Coinductive big-step operational semantics Xavier Leroy a, Hervé Grall b a INRIA Paris-Rocquencourt Domaine de Voluceau, B.P. 105, 78153 Le Chesnay, France b École des Mines de Nantes La Chantrerie, 4,

More information

Trust in the λ-calculus

Trust in the λ-calculus J. Functional Programming, 3(2):75-85, 1997. c Cambridge University Press 1 Trust in the λ-calculus P. ØRBÆK AND J. PALSBERG BRICS, Centre of the Danish National Research Foundation, Dept. of Computer

More information

Integer Clocks and Local Time Scales

Integer Clocks and Local Time Scales Integer Clocks and Local Time Scales Part I Part II Adrien Guatto ENS - PARKAS SYNCHRON 2014 Adrien Guatto (ENS - PARKAS) Integer Clocks and Local Time Scales SYNCHRON 2014 1 / 31 Part I Adrien Guatto

More information

On Typability for Rank-2 Intersection Types with Polymorphic Recursion

On Typability for Rank-2 Intersection Types with Polymorphic Recursion On Typability for Rank-2 Intersection Types with Polymorphic Recursion Tachio Terauchi EECS Department University of California, Berkeley Alex Aiken Computer Science Department Stanford University Abstract

More information

CIS 500 Software Foundations. Final Exam. May 9, Answer key. Hoare Logic

CIS 500 Software Foundations. Final Exam. May 9, Answer key. Hoare Logic CIS 500 Software Foundations Final Exam May 9, 2011 Answer key Hoare Logic 1. (7 points) What does it mean to say that the Hoare triple {{P}} c {{Q}} is valid? Answer: {{P}} c {{Q}} means that, for any

More information

Lecture 13: Turing Machine

Lecture 13: Turing Machine Lecture 13: Turing Machine Instructor: Ketan Mulmuley Scriber: Yuan Li February 19, 2015 Turing machine is an abstract machine which in principle can simulate any computation in nature. Church-Turing Thesis:

More information

Automatic Code Generation

Automatic Code Generation Automatic Code Generation Several tools allow automatic code generation from high-level control models: Simulink Real-Time Workshop (Mathworks) Scicos (Inria) Lustre/SCADE (Verimag/Esterel-Tecnologies)

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 2b Andrew Tolmach Portland State University 1994-2017 Semantics Informal vs. Formal Informal semantics Descriptions in English (or other natural language)

More information

Safety Analysis versus Type Inference

Safety Analysis versus Type Inference Information and Computation, 118(1):128 141, 1995. Safety Analysis versus Type Inference Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus

More information

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth Today 1. What is the Lambda Calculus? Type Systems 2. Its Syntax and Semantics 3. Church Booleans and Church Numerals 4. Lazy vs. Eager Evaluation (call-by-name vs. call-by-value) Lecture 2 Oct. 27th,

More information

Axiomatic Semantics. Semantics of Programming Languages course. Joosep Rõõmusaare

Axiomatic Semantics. Semantics of Programming Languages course. Joosep Rõõmusaare Axiomatic Semantics Semantics of Programming Languages course Joosep Rõõmusaare 2014 Direct Proofs of Program Correctness Partial correctness properties are properties expressing that if a given program

More information

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers 1 Introduction In this lecture, we make an attempt to extend the typed λ-calculus for it to support more advanced data structures

More information

References. 7 November. Fall Software Foundations CIS 500. Another example. Announcements. Homework 7 out today, due November 14.

References. 7 November. Fall Software Foundations CIS 500. Another example. Announcements. Homework 7 out today, due November 14. CIS 500 Software Foundations Fall 2005 7 November CIS 500, 7 November 1 References CIS 500, 7 November 3 Announcements Midterm II is one week from Wednesday (November 16). It will cover TAPL chapters 8-14

More information

Information Flow Analysis via Path Condition Refinement

Information Flow Analysis via Path Condition Refinement Information Flow Analysis via Path Condition Refinement Mana Taghdiri, Gregor Snelting, Carsten Sinz Karlsruhe Institute of Technology, Germany FAST September 16, 2010 KIT University of the State of Baden-Wuerttemberg

More information

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures CS 6110 S18 Lecture 21 Products, Sums, and Other Datatypes 1 Introduction In this lecture, we add constructs to the typed λ-calculus that allow working with more complicated data structures, such as pairs,

More information

Static Program Analysis using Abstract Interpretation

Static Program Analysis using Abstract Interpretation Static Program Analysis using Abstract Interpretation Introduction Static Program Analysis Static program analysis consists of automatically discovering properties of a program that hold for all possible

More information

Operational reasoning for functions with local state

Operational reasoning for functions with local state Operational reasoning for functions with local state Andrew Pitts and Ian Stark Abstract Languages such as ML or Lisp permit the use of recursively defined function expressions with locally declared storage

More information

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 P. 1 of 7 THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 December, 2016 Time: 2 hrs. Instructions The exam contains questions totaling 100 points. Answer all questions.

More information

Lock Inference for Atomic Sections

Lock Inference for Atomic Sections Lock Inference for Atomic Sections Michael Hicks University of Maryland, College Park mwh@cs.umd.edu Jeffrey S. Foster University of Maryland, College Park jfoster@cs.umd.edu Polyvios Pratikakis University

More information

High-Level Small-Step Operational Semantics for Transactions (Technical Companion)

High-Level Small-Step Operational Semantics for Transactions (Technical Companion) High-Level Small-Step Operational Semantics for Transactions (Technical Companion) Katherine F. Moore, Dan Grossman July 15, 2007 Abstract This document is the technical companion to our POPL 08 submission

More information

(Type) Constraints. Solving constraints Type inference

(Type) Constraints. Solving constraints Type inference A (quick) tour of ML F (Graphic) Types (Type) Constraints Solving constraints Type inference Type Soundness A Fully Graphical Presentation of ML F Didier Rémy & Boris Yakobowski Didier Le Botlan INRIA

More information

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University Prof. Mi Lu TA: Ehsan Rohani Laboratory Exercise #4 MIPS Assembly and Simulation

More information

Induction; Operational Semantics. Fall Software Foundations CIS 500

Induction; Operational Semantics. Fall Software Foundations CIS 500 CIS 500 Software Foundations Fall 2005 Induction; Operational Semantics CIS 500, Induction; Operational Semantics 1 Announcements Review recitations start this week. You may go to any recitation section

More information

Combining Effects and Coeffects via Grading (slides)

Combining Effects and Coeffects via Grading (slides) Combining Effects and Coeffects via Grading (slides) Marco Gaboardi SUNY Buffalo, USA Shin-ya Katsumata Kyoto University, Japan Dominic Orchard University of Kent, UK Flavien Breuvart INRA Sophia Antipolis,

More information

Mathematical Foundations of Programming. Nicolai Kraus. Draft of February 15, 2018

Mathematical Foundations of Programming. Nicolai Kraus. Draft of February 15, 2018 Very short lecture notes: Mathematical Foundations of Programming University of Nottingham, Computer Science, module code G54FOP, Spring 2018 Nicolai Kraus Draft of February 15, 2018 What is this? This

More information

Lectures on Separation Logic. Lecture 2: Foundations

Lectures on Separation Logic. Lecture 2: Foundations Lectures on Separation Logic. Lecture 2: Foundations Peter O Hearn Queen Mary, University of London Marktoberdorf Summer School, 2011 Outline for this lecture Part I : Assertions and Their Semantics Part

More information

Tutorial on Semantics Part I

Tutorial on Semantics Part I Tutorial on Semantics Part I Basic Concepts Prakash Panangaden 1 1 School of Computer Science McGill University on sabbatical leave at Department of Computer Science Oxford University Fields Institute,

More information

Informal Statement Calculus

Informal Statement Calculus FOUNDATIONS OF MATHEMATICS Branches of Logic 1. Theory of Computations (i.e. Recursion Theory). 2. Proof Theory. 3. Model Theory. 4. Set Theory. Informal Statement Calculus STATEMENTS AND CONNECTIVES Example

More information

Towards Algorithmic Synthesis of Synchronization for Shared-Memory Concurrent Programs

Towards Algorithmic Synthesis of Synchronization for Shared-Memory Concurrent Programs Towards Algorithmic Synthesis of Synchronization for Shared-Memory Concurrent Programs Roopsha Samanta The University of Texas at Austin July 6, 2012 Roopsha Samanta Algorithmic Synthesis of Synchronization

More information

Denotational semantics

Denotational semantics Denotational semantics The method define syntax (syntactic domains) define semantic domains define semantic functions use compositional definitions Andrzej Tarlecki: Semantics & Verification - 63 - Syntactic

More information

Contracts made manifest

Contracts made manifest JFP: page 1 of 50. c Cambridge University Press 2012 doi:10.1017/s0956796812000135 1 Contracts made manifest MICHAEL GREENBERG, BENJAMIN C. PIERCE and STEPHANIE WEIRICH University of Pennsylvania, Philadelphia,

More information