Costly software bugs that could have been averted with type checking

Size: px
Start display at page:

Download "Costly software bugs that could have been averted with type checking"

Transcription

1 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 the chapters covered: Motivation (Chapter 1) Untyped Arithmetic Expressions (Chapter 3) Typed Arithmetic Expressions (Chapter 8) Untyped Lambda Calculus (Chapter 5) Typed Lambda Calculus (Chapter 9) Motivation Costly software bugs that could have been averted with type checking Ariane 5: On June 4, 1996, the first test flight of the European Ariane 5 rocket veered off its flight path 37 seconds after launch, causing it to self destruct. The bug was an unsafe conversion of a 64 bit floating point number to a 16 bit signed integer which resulted in an uncaught arithmetic overflow. Mars Climate Orbiter: On September 23, 1999, the Mars Climate Orbiter spacecraft reached Mars and began maneuvering into orbit. A navigation error resulted in the spacecraft entering the orbit at a much lower altitude with the spacecraft being destroyed by the higher atmospheric pressures. The bug was in the ambiguity of a software interface the calling component was using imperial units (pound force) and the callee component was expecting metric units (newton). The Challenges of Program Verification We saw even simple software bugs can be very costly. Type checking is an attempt to detect these simple bugs in a more tractable manner. There are several challenges: Specification of software behavior Reasoning about logical formulas The programmer s burden of adding annotations to programs Software is dynamic source code constantly changes Automatic inference of invariants from code, reducing the programmer s burden of annotation. Making good use of lightweight annotations, again reducing the programmer s burden. What is a Type System? A very broad definition is: a tractable syntactic method for proving absence of certain program behaviors by classifying phrases to the kinds they compute. There is no consensus on what is a type. Possible definitions include: Sets of values: o The Integer type is the set of all integers: {0, 1, 1, 2, 2, } o The Boolean type is the set of all Booleans: {True, False}

2 o The Person type is the set of all person records. Sets of legal operations (which can be applied to values of the type): o The Integer type is the set of arithmetic operations: addition, negation, multiplication, etc. o The Boolean type is the set of logical operations: And, Or, Xor, etc. o The Person type is the set of operations applicable to a person: SetName, GetName, GetAge, etc. Static Type Checking We re discussing static type checking specifically. This is type checking which is done before the program is executed, usually by the compiler, during compile time. This analysis is very conservative. It will catch all type errors (it is sound), but will often find errors where there are none. Consider this example: if (5 < 2) AND ( abcde.endswith( de )) then 5 else ok The type checker will report a type error when checking the above phrase, because the type of 5 is Integer and the type of ok is String, which do not match. This is even though the condition is always false and the expression s value is always 5. The type checker will only check that the condition s type is Boolean without looking at its value. Type checking is a static analysis which is usually limited to checking very simple program properties, basically that an operation is legal on a specified expression. Some interesting properties are usually out of scope for a type checker: array out of bound, division by zero, null dereference. Benefits of Type Checking However, type checking can still be very effective. Examples of programmer errors which a type checker can catch: Interface errors: sending the wrong kind of parameter to a function. Dimension analysis: proper conversion between units. Logical errors: proper conversion between different representations. These errors often occur as a result of a change in one part of the program. The type checker can find many other parts of the program which require changing as a result. In this way, the type checker is guiding the programmer. A good type checker encourages usage of types, which increases modularity and eases program integration and code reuse. Types also aid in understanding programs. They are a form of documentation which is automatically checked for correctness. Language Safety A safe programming language makes sure that the language abstractions are never broken. This can be achieved by type safety. An informal definition (Saraswat): A language is type safe if the only operations that can be performed on data in the language are those sanctioned by the type of the data. A categorization of type checked languages: Statically Checked Dynamically Checked Safe ML, Haskell, Java, C# Visual Basic, Lisp, Scheme, Perl, Python, JavaScript Unsafe C, C++

3 C is an unsafe language. Consider the following code: int x=5; char y[] = ok ; char* z = x + y; After running this code, z points to a memory address five characters beyond y, equivalent to two characters after the terminating zero character of the string pointed to by y. The content of that location is undefined. Typically, dereferencing z at this location will cause the program to crash or worth than that access data of different procedures But type safety is not easy to prove. Even though Java is considered a type safe language, there is debate on this topic going on for over 10 years.

4 Untyped Arithmetic Expressions This is a small language of Integers and Booleans. There are no variables and no state. It is just a simple example. Syntax Inductive definition of terms: t ::= terms: True constant true False constant false if t then t else t conditional 0 constant zero succ t successor pred t predecessor iszero t zero test Programs in this language are just terms built from the grammar above. To keep things short, we use standard numerals for numbers which are formally represented as nested applications of succ to 0. For example, succ(succ(succ(0))) is written as 3. For example, evaluating the term if false then 0 else 1 yields 1. Evaluating the term iszero (pred (succ 0)) yields true. Even with this simple language we can have type errors. Evaluating the following terms results in type errors: succ true if 0 then 0 else 0 iszero( iszero( 0 ) ) Structural Operational Semantics We use small step operational semantics for evaluating the untyped arithmetic expressions language. Inductive definitions of values: v ::= True False Nv values: true value false value numeric value nv ::= numeric values: 0 zero value succ nv successor value Evaluation rules:

5 E IFFALSE E IFTRUE E IF E SUCC E PREDZERO E PREDSUCC E PRED E ISZEROZERO E ISZEROSUCC E ISZERO There are no rules for variables because there are no assignments in this language, and no state.

6 Typed Arithmetic Expressions As we saw before, even in the simple arithmetic expressions language we can have type errors at run time. With some expressions, as we evaluate them we can get to weird results where we don t know how to continue with the evaluation. We re stuck. Adding a type system will allow us to determine that we will not have run time errors, without evaluating ( running ) the expressions. The compiler proves that there will be no run time errors. Again, the type system itself is nearly trivial. Stuck Computations and Safety The compiler proves the absence of run time errors by showing that every term is welltyped that every term has a type. Separately, we prove that the type system is safe (sound). The two claims together (type system safety and well typed terms) show that there will be no run time errors. What is a safe type system? It has the following two properties: Progress: A well typed term t is never stuck. Either it has a value, or there exists a term t such that there s a reduction t d t. Preservation: If a well typed term takes a step in evaluation, then the resulting term is also well typed. We can see from this definition of safety, that if we start the evaluation with well typed terms, we won t get stuck no run time errors. Type Rules The available types: T ::= Bool Nat Type calculation rules: Rule name T TRUE T FALSE T IF T ZERO T SUCC types: type of Booleans type of Natural numbers t : T T PRED T ISZERO Note how in the rule T IF the type of the expression depends on a parameter T. This rule enforces that both branches of the IF expression have the same type, but it can be any type, depending on the type of its subexpressions.

7 The Typing Relation The typing relation is a binary relation between terms and types. We denote the typing relation with :. A term t is typable (well typed) if there exists some type T such that t:t, according to the above type rules. We want the typing relation to be minimal, in the sense that we do not place more restrictions beyond the ones implied by the rules term. It remains to be proven that in the arithmetic expressions type system there is a unique minimal typing relation there is at most one possible type for every term. The type rules specify the type of complex terms by the types of their subterms. This typing system is easily inverted we can tell the type of subterms from the type of the complex term. This implies that calculating types in this language is easy. We can use a linear time (in the size of the expression) algorithm that checks an expression is well typed. Inverting the type system is more difficult in more complex languages. A theorem says that if the type system is invertible, then there is a unique typing relation. The proof is through structural induction on the expressions, and using the type rules inversion. Safety [Pierce page 95] We want to show that this type system is safe. That is, that the two safety properties hold: Progress: if t is a well typed term then t is either a value or there is an evaluation rule which can be applied to t. Preservation: if t has type T, and t is derived through an evaluation rule from t, then t has type T. To show these, we first show the canonical forms, the kinds of values which each type can have. If v is a value of type Bool, then according to the type rules, v is either true or false. If v is a value of type Nat, then v is not true or false. Therefore, v is a numeric value. Now we show the progress property. If t is a well typed term of type T, then there s a type derivation sequence for t. The proof proceeds by induction on the type derivation sequence. We assume the property holds for all type derivation sequences shorter than the type derivation sequence of t, and show the progress property holds for t. We check the last step in the type derivation sequence, and prove the property holds for every possible rule used in the last step. We only explain the case where last rule used is T IF. The other cases are simpler (Pierce contains the full proof). As the last rule is T IF, the term t is if t 1 then t 2 else t 3, and t 1 is of type Bool. By the induction hypothesis, the progress property holds for t 1. Therefore, t 1 is either a value, or an evaluation rule can be applied to t 1. If t 1 is a value, then, by the canonical forms, t 1 is either true or false. In the first case, the evaluation rule E IFTRUE can be applied to t. In the second case, the evaluation rule E IFFALSE can be applied. Otherwise, an evaluation rule can be applied to t 1. In this case, the evaluation rule E IF can be applied to t. The proof of the preservation property proceeds in the same manner.

8 Untyped Lambda calculus Lambda calculus has widespread use in the specification of programming language features, in language design and implementation, and in the study of type systems. Its importance arises from the fact that it can be viewed simultaneously as a simple programming language in which computations can be described and as a mathematical object about which rigorous statements can be proved. It embodies definition and application in the purest possible form, though compact to make it suitable for our purposes. In the lambda calculus everything is a function: the arguments accepted by function are themselves function and the results returned by a function is another function. Syntax t ::= Terms X Variable λ x.t Abstraction t t Application The syntax of the lambda calculus comprises three sorts of terms: variables, abstractions, and applications. For example λ x.x is an abstraction that represents the identity function (It receives x as an argument and returns it). Another example is (λ x.x)( λ x.x) which is an application of two terms that returns a term representing the identity function. Note that the terms should be parsed in a left right manner (i.e. start from the left and end on the right). The scope of variable in lambda calculus can be described in terms of binders. An occurrence of a variable x is said to be bound when it appears in the body of an abstraction λ x.t (i.e. in t). Equivalently, λ x is a binder with the scope t. An occurrence of x is said to be free if it doesn't appear in a binding scope λ x. Examples: 1) The occurrence of x in following is free: a. λ y. x y b. x y 2) The occurrence of x in the following is bound: a. λ x.x b. λ z. λ x. λ y. x (y z) 3) The first occurrence of x in the following statement is bound and the second is free: a. (λ x.x) x A term without free variables is said to be closed, and often called combinator. The simplest combinator is the identity function (λ x.x). Operational Semantics In its pure form, the sole means by which terms are computed in the lambda calculus is the application of functions to arguments (which themselves are functions).

9 The beta reduction: A term of the form (λ x.t 12 )t 2 is called a redex ( reducible expression ), and the operation of rewriting a redex according to the following rule is called a beta reduction: (λ x.t 1 )t 2 [x t 2 ]t 1 where [x t 2 ]t 1 means the term obtained by replacing all free occurrences of x with t 2 in t 1. Examples: 1) (λ x.x) y y notice that y stands for t 2 and the right x stands for t 1, now we replace all free occurrences of x in x with y). 2) (λ x.x (λ x.x))(u r) (u r)(λ x.x) Here t 2 is (u r) and t 1 is x (λ x.x), notice that x is bounded in (λ x.x) and thus is not being replaced. The beta reduction can be formulated as follows: 1) [x s]x = s 2) [x s]y = y, where y x 3) [x s] t 1 t 2 = ([x s] t 1 )( [x s] t 2 ). 4) [x s] λ y.t 1 = λ y. [x s] t 1, where x y and y is not in FV(s), the set of free variables in the expression s. Note that the final rule does not limit our computation. If a variable is bounded we can perform an alpha reduction to rename the bounded variable: (λ x. (λ y.x y))(y z) (λ x. (λ w.x w))(y z) λ w.y z w The beta reduction can be used in several different evaluations orders that cover all kinds of evaluations in programming languages: 1) Full beta reduction: Any redex may be reduced at any time. 2) Normal order: The leftmost, outermost redex is always reduced first. 3) Call by name: Normal order with the restriction of not allowing reductions inside abstraction. 4) Call by value: Used by most of the programming languages, means that only the outmost redexes are reduced, and a redex is reduced only when its right and side has already been reduced to a value (i.e. can't be reduced anymore) Programming in the lambda calculus The lambda calculus is much more powerful than its tiny definition might suggest. The following are examples of how we can implement some standard features of high level programming languages: 1) Multiple arguments: The lambda calculus has no built it support for multi argument functions. Of course it isn't hard to add this. Suppose that s is a term involving the free variables x and y, and that we want to evaluate a function that for each pair (v,w) of arguments, substitute x with v and y with w. instead of writing f = λ(x,y).s we write f = λx. λy.s, i.e. f is a function that, given a value v for x, yields a function that, given a value w for y, yields the desired result. 2) Church Booleans: Another language feature that can easily be encoded in the lambda calculus is Boolean values and conditions. We define the terms tru and fls as follows: a. tru = λt. λf. t can be viewed as a functions yielding t for the arguments t and f.

10 b. fls = λt. λf. f can be viewed as a functions yielding f for the arguments t and f. The terms tru and fls represent the Boolean values true and false in the sense that we can use these terms to perform the operation of testing the truth of a Boolean value. In particular, we can use application to define a combinator test with the following property: test b v w, reduces to v when b is tru. test b v w, reduces to w when b is fls. Where test = λl. λm. λn l m n. This combinator doesn't do much. It just reduces test b v w to b v w. The Boolean b itself is the conditional, it takes two arguments and chooses the first if it is tru, and the second if it is fls. For example the term test tru v w reduces as follows: test tru v w tru v w v 3) Pairs: Using booleans, we can encode pairs of values as follows: pair = λf. λs. λb. b f s first = λp. p tru second = λp. p fls 4) Church Numbers: Representation of numbers by lambda calculus is only slightly more intricate, the numbers c 0, c 1, c 2 etc. as follows: c 0 = λs. λz. z c 1 = λs. λz. s z c 2 = λs. λz. s(s z) etc. A number n is represented by a combinator c n that takes two arguments, s and z (s for successor and z for zero). The number is encoded in the count of repeated applications of s to z. As an example of how to compute with Church Numbers, here is the plus operator: plus = λm. λn. λs. λz. (m s)( n s z) Simply Typed Lambda calculus Suppose we want to construct a type system for a language combining Booleans with primitives of the pure lambda calculus. That is, we want to introduce typing rules for variables, abstractions, and applications that: a) Maintain type safety, i.e. satisfy the preservation and progress theorem. b) Are not too conservative, i.e. they could assign types to most of the programs we actually care about writing. Syntax t ::= X λ x:t.t t t Terms Variable Abstraction Application T ::= T T Types Types of functions

11 v ::= λx:t.t values Abstraction values Γ:= Context Empty context Γ, x : T Term variable binding Operational Semantics Evaluation (t t'): Rule name Rule description E APP1 t1 t 1' t 1 t 2 t' 1 t2 E APP2 t2 t 2' t 1 t 2 t 1 t' 2 E APPABS (λx:t 11. t 12 ) v 2 [x v 2 ] t 12 Typing (Γ t:t): Rule name Rule description T VAR x: T Γ Γ x:t T ABS Γ,x:T 1 t 2:T2 Γ λx:t 1. t 2:T 2 :T 1 T2 T APP Γ t 1:T11 T 12 Γ t 2:T11 Γ t1 t 2 :T12 Note that Γ is a table of symbols, that maps between variables and types. Extension for Booleans To extend the type system for Booleans to include functions, we clearly need to add a type classifying terms whose evaluation results in a function. Grammar: T:= Bool T T Types Types of Booleans Types of functions Examples: a) (λx:bool. x) true A Bool type. b) If true then (λx:bool. x) else (λx:bool. x) A Bool type. c) If true then (λx:bool. x) else (λx:bool. λy:bool. x) Type is undefined.

12 The typing relation In order to assign type to an abstraction, we need to calculate what will happen when the abstraction is applied to some argument. In addition we want to determine what type we are expecting to get. Formally the Typing relation is the smallest ternary relation on contexts, terms, and types. We say that a term t is typeble (well typed), in a given context Γ if there exists some type T, such that Γ t:t. Inversions of the typing relation a) Γ x : R x: R Γ b) Γ λx :T 1. t 2 : R R = T 1 R 2 for some R 2 with Γ t 2 : R 2 c) Γ t 1 t 2 : R there exists T 11 such that Γ t 1 : T 11 R and Γ t 2 : T 11 d) Γ true : R R = Bool e) Γ false : R R = Bool f) Γ if t 1 then t 2 else t 3 : R Γ t 1 : Bool, Γ t 2 : R, Γ t 3 : R A proof for the inversions is directly derived from the definition of the typing relation. Uniqueness of types In a given context, a term t has at most one type. That is, if a term is typeble, then its type is unique. Moreover, there is just one derivation of this typing built from the type inference rules that generate the typing relation. Safety a) Canonical Forms: a. If v is a value of type Bool, then v is either true or false. b. If v is a value of type T 1 T 2, then v = λx:t 1.t 2 b) Progress: Suppose t is a closed, well typed term (that is, t : T for some T). Then either t is a value or else there is some t' with t t' c) Permutation: If Γ t :T and Δ is a permutation of Γ, then Δ t : T. Moreover, the latter derivation has the same depth as the former d) Weakening: If Γ t :T and x dom(γ), then Γ, x:s t : T. e) Preservation of types under substitution: If Γ, x:s t:t and Γ s:s then Γ [x s] t:t f) Preservation: If Γ t:t and t t then Γ t : T We should note that within this type system the programmers can omit types as long as the resulting type is unique. Thus we should ensure that there are enough different types, so we get a unique type. In addition, a type inference algorithm on this type system infers a unique type or issues an error.

13 Extensions a) Sub typing b) Recursive types c) Polymorphism d) Higher order systems Summary Type systems enable to enforce certain safety properties on the programmer, and can be combined with run time systems and program analysis. It interacts with the programmer during the compilation process, and has a lot of interesting theory built upon it.

CIS 500 Software Foundations Midterm I

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

Programming Languages Fall 2014

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

More information

CIS 500 Software Foundations Fall October 2

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

More information

CIS 500 Software Foundations Midterm I Answer key October 8, 2003

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

CIS 500 Software Foundations Fall September 25

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

Chapter 5: The Untyped Lambda Calculus

Chapter 5: The Untyped Lambda Calculus Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus

More information

Type Systems Winter Semester 2006

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

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

The 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 information

Concepts of programming languages

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.

More information

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

Fall 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 information

Lecture 9: Typed Lambda Calculus

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

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

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

More information

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 CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008 Contents 1 Solution to the Exercise 1 1.1 Semantics for lambda calculus.......................

More information

Formal Systems and their Applications

Formal 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 information

(Advanced) topics in Programming Languages

(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 information

Chapter 5: The Untyped Lambda Calculus

Chapter 5: The Untyped Lambda Calculus Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus

More information

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE

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

Lesson 4 Typed Arithmetic Typed Lambda Calculus

Lesson 4 Typed Arithmetic Typed Lambda Calculus Lesson 4 Typed Arithmetic Typed Lambda 1/28/03 Chapters 8, 9, 10 Outline Types for Arithmetic types the typing relation safety = progress + preservation The simply typed lambda calculus Function types

More information

More Lambda Calculus and Intro to Type Systems

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

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Advanced Topics in Programming Languages Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming

More information

Simply-Typed Lambda Calculus

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

More information

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λ-calculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Concepts in Programming Languages Recitation 5: Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and

More information

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

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,

More information

The 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 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 information

Programming Languages

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

More information

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

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

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

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:

More information

Fundamental Concepts. Chapter 1

Fundamental Concepts. Chapter 1 Chapter 1 Fundamental Concepts This book is about the mathematical foundations of programming, with a special attention on computing with infinite objects. How can mathematics help in programming? There

More information

More Lambda Calculus and Intro to Type Systems

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

More information

CSE 505: Concepts of Programming Languages

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

More information

1 Introduction. 3 Syntax

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,

More information

Programming Languages. Programming with λ-calculus. Lecture 11: Type Systems. Special Hour to discuss HW? if-then-else int

Programming Languages. Programming with λ-calculus. Lecture 11: Type Systems. Special Hour to discuss HW? if-then-else int CSE 230: Winter 2010 Principles of Programming Languages Lecture 11: Type Systems News New HW up soon Special Hour to discuss HW? Ranjit Jhala UC San Diego Programming with λ-calculus Encode: bool if-then-else

More information

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. Adding data structures. Data + Code. What about functions Whereweare CS-XXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

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

More information

Introduction to the Lambda Calculus

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

More information

CIS 500 Software Foundations Midterm II Answer key November 16, 2005

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

More information

Lambda Calculus and Type Inference

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

Lambda Calculi With Polymorphism

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 information

Lambda Calculi With Polymorphism

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 information

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

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 9 Simply Typed Lambda Calculus Dan Grossman 2012 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our

More information

1 Scope, Bound and Free Occurrences, Closed Terms

1 Scope, Bound and Free Occurrences, Closed Terms CS 6110 S18 Lecture 2 The λ-calculus Last time we introduced the λ-calculus, a mathematical system for studying the interaction of functional abstraction and functional application. We discussed the syntax

More information

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

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... 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 information

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

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)

More information

The Untyped Lambda Calculus

The 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 information

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

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 3: Induction Prof. Liang Huang huang@qc.cs.cuny.edu Recursive Data Types (trees) data Ast = ANum Integer APlus Ast Ast ATimes Ast Ast eval (ANum x) = x eval (ATimes

More information

Pure Lambda Calculus. Lecture 17

Pure Lambda Calculus. Lecture 17 Pure Lambda Calculus Lecture 17 Lambda Calculus Lambda Calculus (λ-calculus) is a functional notation introduced by Alonzo Church in the early 1930s to formalize the notion of computability. Pure λ-calculus

More information

The Untyped Lambda Calculus

The 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 information

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped) 1 LAMBDA CALCULUS (untyped) 2 The Untyped Lambda Calculus (λ) Designed by Alonzo Church (1930s) Turing Complete (Turing was his doctoral student!) Models functions, always as 1-input Definition: terms,

More information

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility λ Calculus Church s λ Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ August 17, 2007 Lambda Calculus and Type

More information

Fundamentals and lambda calculus

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 information

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

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)

More information

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

Formal Semantics. Aspects to formalize. Lambda calculus. Approach Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and

More information

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

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

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Polymorphic 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 information

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively

More information

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

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

More information

CMSC 330: Organization of Programming Languages

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

More information

Lecture 9: More Lambda Calculus / Types

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

More information

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

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

Lambda Calculus. Concepts in Programming Languages Recitation 6:

Lambda Calculus. Concepts in Programming Languages Recitation 6: Concepts in Programming Languages Recitation 6: Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming

More information

CMSC 330: Organization of Programming Languages

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

More information

CSE-321 Programming Languages 2012 Midterm

CSE-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 information

CSE-321 Programming Languages 2010 Midterm

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

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Why study? Lambda calculus Syntax Evaluation Relationship to programming languages Church Rosser theorem Completeness of Lambda Calculus: Turing

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce 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 information

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

5. Introduction to the Lambda Calculus. Oscar Nierstrasz 5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming

More information

Lambda Calculus. Lecture 4 CS /26/10

Lambda Calculus. Lecture 4 CS /26/10 Lambda Calculus Lecture 4 CS 565 10/26/10 Pure (Untyped) Lambda Calculus The only value is a function Variables denote functions Functions always take functions as arguments Functions always return functions

More information

Functional Languages and Higher-Order Functions

Functional 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

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

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

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

More Untyped Lambda Calculus & Simply Typed Lambda Calculus Concepts in Programming Languages Recitation 6: More Untyped Lambda Calculus & Simply Typed Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky,

More information

CITS3211 FUNCTIONAL PROGRAMMING. 10. Programming in the pure λ calculus

CITS3211 FUNCTIONAL PROGRAMMING. 10. Programming in the pure λ calculus CITS3211 FUNCTIONAL PROGRAMMING 10. Programming in the pure λ calculus Summary: This lecture demonstates the power of the pure λ calculus by showing that there are λ expressions that can be used to emulate

More information

The Untyped Lambda Calculus

The 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 information

The Untyped Lambda Calculus

The 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 information

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

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

More information

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

Last 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 information

COS 320. Compiling Techniques

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

More information

Type Systems. Parametric Polymorphism. 1. Recall Let-Polymorphism. 1. Recall Let-Polymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth

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

Lambda Calculus. Variables and Functions. cs3723 1

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

More information

More Lambda Calculus and Intro to Type Systems

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

More information

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010 Pure (Untyped) λ-calculus Andrey Kruglyak, 2010 1 Pure (untyped) λ-calculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential

More information

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. Let bindings (CBV) Adding Stuff. Booleans and Conditionals Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:

More information

Type Systems Winter Semester 2006

Type 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

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

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

More information

dynamically typed dynamically scoped

dynamically typed dynamically scoped Reference Dynamically Typed Programming Languages Part 1: The Untyped λ-calculus Jim Royer CIS 352 April 19, 2018 Practical Foundations for Programming Languages, 2/e, Part VI: Dynamic Types, by Robert

More information

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

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

More information

Programming Languages Lecture 14: Sum, Product, Recursive Types

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

More information

Lecture Notes on Data Representation

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

More information

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1 Lecture #3: Lambda Calculus Last modified: Sat Mar 25 04:05:39 2017 CS198: Extra Lecture #3 1 Simplifying Python Python is full of features. Most are there to make programming concise and clear. Some are

More information

Typed Lambda Calculus and Exception Handling

Typed Lambda Calculus and Exception Handling Typed Lambda Calculus and Exception Handling Dan Zingaro zingard@mcmaster.ca McMaster University Typed Lambda Calculus and Exception Handling p. 1/2 Untyped Lambda Calculus Goal is to introduce typing

More information

Subsumption. Principle of safe substitution

Subsumption. 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 information

Lambda Calculus: Implementation Techniques and a Proof. COS 441 Slides 15

Lambda Calculus: Implementation Techniques and a Proof. COS 441 Slides 15 Lambda Calculus: Implementation Techniques and a Proof COS 441 Slides 15 Last Time: The Lambda Calculus A language of pure functions: values e ::= x \x.e e e v ::= \x.e With a call-by-value operational

More information

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson Lambda Calculus CS 550 Programming Languages Jeremy Johnson 1 Lambda Calculus The semantics of a pure functional programming language can be mathematically described by a substitution process that mimics

More information

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004 CMPUT 325 : Lambda Calculus Basics Dr. B. Price and Dr. R. Greiner 13th October 2004 Dr. B. Price and Dr. R. Greiner CMPUT 325 : Lambda Calculus Basics 1 Lambda Calculus Lambda calculus serves as a formal

More information

CS4215 Programming Language Implementation. Martin Henz

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

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm Gradescope ID: (Gradescope ID is the First letter of your last name and last 5 digits of your UID) (If you write your name on the test, or your gradescope ID

More information

An Introduction to the Lambda Calculus

An Introduction to the Lambda Calculus Department of Computer Science Australian National University COMP3610 Principles of Programming Languages An Introduction to the Lambda Calculus Clem Baker-Finch August 13, 2013 Contents 1 Motivation

More information