# Simply-Typed Lambda Calculus

Size: px
Start display at page:

## Transcription

1 #1 Simply-Typed Lambda Calculus

2 #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 is a verification condition?

3 #3 Today s (Short?) Cunning Plan Type System Overview First-Order Type Systems Typing Rules Typing Derivations Type Safety

4 #4 Types A program variable can assume a range of values during the execution of a program An upper bound of such a range is called a type of the variable A variable of type bool is supposed to assume only boolean values If x has type bool then the boolean expression not(x) has a sensible meaning during every run of the program

5 #5 Typed and Untyped Languages Untyped languages Do not restrict the range of values for a given variable Operations might be applied to inappropriate arguments. The behavior in such cases might be unspecified The pure λ-calculus is an extreme case of an untyped language (however, its behavior is completely specified) (Statically) Typed languages Variables are assigned (non-trivial) types A type system keeps track of types Types might or might not appear in the program itself Languages can be explicitly typed or implicitly typed

6 #6 The Purpose Of Types The foremost purpose of types is to prevent certain types of run-time execution errors Traditional trapped execution errors Cause the computation to stop immediately And are thus well-specified behavior Usually enforced by hardware e.g., Division by zero, floating point op with a NaN e.g., Dereferencing the address 0 (on most systems) Untrapped execution errors Behavior is unspecified (depends on the state of the machine = this is very bad!) e.g., accessing past the end of an array e.g., jumping to an address in the data segment

7 #7 Execution Errors A program is deemed safe if it does not cause untrapped errors Languages in which all programs are safe are safe languages For a given language we can designate a set of forbidden errors A superset of the untrapped errors, usually including some trapped errors as well e.g., null pointer dereference Modern Type System Powers: prevent race conditions (e.g., Flanagan TLDI 05) prevent insecure information flow (e.g., Li POPL 05) prevent resource leaks (e.g., Vault, Weimer) help with generic programming, probabilistic languages, are often combined with dynamic analyses (e.g., CCured)

8 #8 Preventing Forbidden Errors - Static Checking Forbidden errors can be caught by a combination of static and run-time checking Static checking Detects errors early, before testing Types provide the necessary static information for static checking e.g., ML, Modula-3, Java Detecting certain errors statically is undecidable in most languages

9 #9 Preventing Forbidden Errors - Dynamic Checking Required when static checking is undecidable e.g., array-bounds checking Run-time encodings of types are still used (e.g. Lisp) Should be limited since it delays the manifestation of errors Can be done in hardware (e.g. null-pointer)

10 #10 Why Typed Languages? Development Type checking catches early many mistakes Reduced debugging time Typed signatures are a powerful basis for design Typed signatures enable separate compilation Maintenance Types act as checked specifications Types can enforce abstraction Execution Static checking reduces the need for dynamic checking Safe languages are easier to analyze statically the compiler can generate better code

11 Why Not Typed Languages? Static type checking imposes constraints on the programmer Some valid programs might be rejected But often they can be made well-typed easily Hard to step outside the language (e.g. OO programming in a non-oo language, but cf. Ruby, OCaml, etc.) Dynamic safety checks can be costly 50% is a possible cost of bounds-checking in a tight loop In practice, the overall cost is much smaller Memory management must be automatic ) need a garbage collector with the associated run-time costs Some applications are justified in using weakly-typed languages (e.g., by external safety proof) #11

12 #12 Safe Languages There are typed languages that are not safe ( weakly typed languages ) All safe languages use types (static or dynamic) Safe Unsafe Static ML, Java, Ada, C#, Haskell,... C, C++, Pascal,... Typed Dynamic Lisp, Scheme, Ruby, Perl, Smalltalk, PHP, Python, We focus on statically typed languages? Untyped λ-calculus Assembly

13 #13 Properties of Type Systems How do types differ from other program annotations? Types are more precise than comments Types are more easily mechanizable than program specifications Expected properties of type systems: Types should be enforceable Types should be checkable algorithmically Typing rules should be transparent Should be easy to see why a program is not well-typed

14 #14 Why Formal Type Systems? Many typed languages have informal descriptions of the type systems (e.g., in language reference manuals) A fair amount of careful analysis is required to avoid false claims of type safety A formal presentation of a type system is a precise specification of the type checker And allows formal proofs of type safety But even informal knowledge of the principles of type systems help

15 #15 Formalizing a Language 1. Syntax Of expressions (programs) Of types Issues of binding and scoping 2. Static semantics (typing rules) Define the typing judgment and its derivation rules 3. Dynamic Semantics (e.g., operational) Define the evaluation judgment and its derivation rules 4. Type soundness Relates the static and dynamic semantics State and prove the soundness theorem

16 Typing Judgments Judgment (recall) A statement J about certain formal entities Has a truth value ² J Has a derivation ` J (= a proof ) A common form of typing judgment: Γ ` e : τ (e is an expression and τ is a type) Γ (Gamma) is a set of type assignments for the free variables of e Defined by the grammar Γ ::= Γ, x : τ Type assignments for variables not free in e are not relevant e.g, x : int, y : int ` x + y : int #16

17 #17 Typing rules Typing rules are used to derive typing judgments Examples:

18 #18 Typing Derivations A typing derivation is a derivation of a typing judgment (big surprise there ) Example: We say Γ ` e : τ to mean there exists a derivation of this typing judgment (= we can prove it ) Type checking: given Γ, e and τ find a derivation Type inference: given Γ and e, find τ and a derivation

19 Proving Type Soundness A typing judgment is either true or false Define what it means for a value to have a type v 2 k τ k (e.g. 5 2 k int k and true 2 k bool k ) Define what it means for an expression to have a type e 2 j τ j iff 8v. (e v ) v 2 k τ k) Prove type soundness If ` e : τ or equivalently If ` e : τ and e v then e 2 j τ j then v 2 k τ k This implies safe execution (since the result of a unsafe execution is not in k τ k for any τ) #19

20 #20 Upcoming Exciting Episodes We will give formal description of first-order type systems (no type variables) Function types (simply typed λ-calculus) Simple types (integers and booleans) Structured types (products and sums) Imperative types (references and exceptions) Recursive types (linked lists and trees) The type systems of most common languages are first-order Then we move to second-order type systems Polymorphism and abstract types

21 Q: Movies (378 / 842) This 1988 animated movie written and directed by Isao Takahata for Studio Ghibli was considered by Roger Ebert to be one of the most powerful anti-war films ever made. It features Seita and his sister Setsuko and their efforts to survive outside of society during the firebombing of Tokyo.

22 Computer Science This American-Canadian Turing-award winner is known for major contributions to the fields of complexity theory and proof complexity. He is known for formalizing the polynomial-time reduction, NP-completeness, P vs. NP, and showing that SAT is NP-complete. This was all done in the seminal 1971 paper The Complexity of Theorem Proving Procedures.

23 Q: Games (504 / 842) This 1985 falling-blocks computer game was invented by Alexey Pajitnov (Алексей Пажитнов) and inspired by pentominoes.

24 Simply-Typed Lambda Calculus Notice :τ Syntax: Terms e ::= x λx:τ. e e 1 e 2 n e 1 + e 2 iszero e true false not e if e 1 then e 2 else e 3 Types τ ::= int bool τ 1! τ 2 τ 1! τ 2 is the function type! associates to the right Arguments have typing annotations :τ This language is also called F 1 #24

25 #25 Static Semantics of F 1 The typing judgment Γ ` e : τ Some (simpler) typing rules:

26 #26 More Static Semantics of F 1 Why do we have this mysterious gap? I don t know either!

27 #27 Typing Derivation in F 1 Consider the term λx : int. λb : bool. if b then f x else x With the initial typing assignment f : int! Int Where Γ = f : int! int, x : int, b : bool

28 #28 Type Checking in F 1 Type checking is easy because Typing rules are syntax directed Typing rules are compositional (what does this mean?) All local variables are annotated with types In fact, type inference is also easy for F 1 Without type annotations an expression may have no unique type ` λx. x : int! int ` λx. x : bool! bool

29 #29 Operational Semantics of F 1 Judgment: Values: e v v ::= n true false λx:τ. e The evaluation rules Audience participation time: raise your hand and give me an evaluation rule.

30 #30 Opsem of F 1 (Cont.) Call-by-value evaluation rules (sample) Where is the Call-By-Value? How might we change it? Evaluation is undefined for illtyped programs!

31 #31 Type Soundness for F 1 Thm: If ` e : τ and e v then ` v : τ Also called, subject reduction theorem, type preservation theorem This is one of the most important sorts of theorems in PL Whenever you make up a new safe language you are expected to prove this Examples: Vault, TAL, CCured, Proof: next time!

32 #32 Homework Read actually-exciting Leroy paper Finish Homework 5? Work on your projects! Status Update Due

### Simply-Typed Lambda Calculus

#1 Simply-Typed Lambda Calculus #2 The Reading Explain the Xavier Leroy article to me How did he do register allocation? #3 Back to School What is operational semantics? When would you use contextual (small-step)

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

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

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

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

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

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

### Semantic Analysis and Type Checking

Semantic Analysis and Type Checking The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on

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

### In Our Last Exciting Episode

In Our Last Exciting Episode #1 Lessons From Model Checking To find bugs, we need specifications What are some good specifications? To convert a program into a model, we need predicates/invariants and

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

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

### Harvard School of Engineering and Applied Sciences Computer Science 152

Harvard School of Engineering and Applied Sciences Computer Science 152 Lecture 17 Tuesday, March 30, 2010 1 Polymorph means many forms. Polymorphism is the ability of code to be used on values of different

### Recursive Types and Subtyping

Recursive Types and Subtyping #1 One-Slide Summary Recursive types (e.g., list) make the typed lambda calculus as powerful as the untyped lambda calculus. If is a subtype of then any expression of type

### Com S 541. Programming Languages I

Programming Languages I Lecturer: TA: Markus Lumpe Department of Computer Science 113 Atanasoff Hall http://www.cs.iastate.edu/~lumpe/coms541.html TR 12:40-2, W 5 Pramod Bhanu Rama Rao Office hours: TR

### Types for References, Exceptions and Continuations. Review of Subtyping. Γ e:τ τ <:σ Γ e:σ. Annoucements. How s the midterm going?

Types for References, Exceptions and Continuations Annoucements How s the midterm going? Meeting 21, CSCI 5535, Spring 2009 2 One-Slide Summary Review of Subtyping If τ is a subtype of σ then any expression

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

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

### Costly software bugs that could have been averted with type checking

Type Checking Class Notes from Lectures 6 and 7 Lahav Yeffet and Ori Folger The material in these lectures is based on the textbook Types and Programming Languages by Benjamin Pierce. Here is a list of

### Recursive Types and Subtyping

Recursive Types and Subtyping #1 One-Slide Summary Recall: Recursive types (e.g., τ list) make the typed lambda calculus as powerful as the untyped lambda calculus. If τ is a subtype of σ then any expression

### CS558 Programming Languages

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

### Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type

### Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

### CSCE 314 Programming Languages. Type System

CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be

### Second-Order Type Systems

#1 Second-Order Type Systems Homework 5 Summary Student : 37.9704 Student : 44.4466 ORIGINAL : 50.2442 Student : 50.8275 Student : 50.8633 Student : 50.9181 Student : 52.1347 Student : 52.1633 Student

### Programming Languages Lecture 15: Recursive Types & Subtyping

CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)

### CS558 Programming Languages

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

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

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

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

### CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

CS 565: Programming Languages Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106 Administrivia Who am I? Course web page http://www.cs.purdue.edu/homes/peugster/cs565spring08/ Office hours By appointment Main

### The role of semantic analysis in a compiler

Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

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

### Lecture 9: More Lambda Calculus / Types

Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Pure Lambda Calculus Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete

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

Pure Lambda Calculus Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete

### CMSC 330: Organization of Programming Languages. Operational Semantics

CMSC 330: Organization of Programming Languages Operational Semantics Notes about Project 4, Parts 1 & 2 Still due today (7/2) Will not be graded until 7/11 (along with Part 3) You are strongly encouraged

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

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

### Mutable References. Chapter 1

Chapter 1 Mutable References In the (typed or untyped) λ-calculus, or in pure functional languages, a variable is immutable in that once bound to a value as the result of a substitution, its contents never

### Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Type Inference Prof. Clarkson Fall 2016 Today s music: Cool, Calm, and Collected by The Rolling Stones Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax Formal semantics

### Lecture 5: The Untyped λ-calculus

Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,

### Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

### CSCI-GA Scripting Languages

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

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions

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

CMSC 330: Organization of Programming Languages Lambda Calculus Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying or tuples

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying

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

### Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

Chapter 13: Reference Why reference Typing Evaluation Store Typings Safety Notes References Computational Effects Also known as side effects. A function or expression is said to have a side effect if,

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

### Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

### Tradeoffs. CSE 505: Programming Languages. Lecture 15 Subtyping. Where shall we add useful completeness? Where shall we add completeness?

Tradeoffs CSE 505: Programming Languages Lecture 15 Subtyping Zach Tatlock Autumn 2017 Desirable type system properties (desiderata): soundness - exclude all programs that get stuck completeness - include

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 14 Tuesday, March 24, 2015 1 Parametric polymorphism Polymorph means many forms. Polymorphism is the ability of

### Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

### At build time, not application time. Types serve as statically checkable invariants.

Static Typing Thus far we have only considered statically typed languages. CMPSCI 630: Programming Languages Static and Dynamic Typing Spring 2008 (with thanks to Robert Harper) Type system is based on

### Concepts of Programming Languages

Concepts of Programming Languages Lecture 1 - Introduction Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014

### G Programming Languages - Fall 2012

G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

### Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Type Checking Outline General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

### Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

### Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Types 1 / 15 Outline Introduction Concepts and terminology The case for static typing Implementing a static type system Basic typing relations Adding context 2 / 15 Types and type errors Type: a set of

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

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

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

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

### Types and Type Inference

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

### 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

### Denotational Semantics. Domain Theory

Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning

### Introduction to System F. Lecture 18 CS 565 4/20/09

Introduction to System F Lecture 18 CS 565 4/20/09 The Limitations of F 1 (simply-typed λ- calculus) In F 1 each function works exactly for one type Example: the identity function id = λx:τ. x : τ τ We

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

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

### Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

CS 6110 S18 Lecture 8 Structural Operational Semantics and IMP Today we introduce a very simple imperative language, IMP, along with two systems of rules for evaluation called small-step and big-step semantics.

### Type Checking and Type Inference

Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

### CS558 Programming Languages

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

### Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan" " Chapter 1" Overview" " A good programming language is a conceptual universe for thinking about programming. " " " " " " " " " " " " "A. Perlis" "

### CMSC330. Objects, Functional Programming, and lambda calculus

CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Object-oriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed

### CS 242. Fundamentals. Reading: See last slide

CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

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

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

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

### Today s Class. Programming Languages Topic of Ultimate Mastery. Reasonable Initial Skepticism. Meta-Level Information

Programming Languages Topic of Ultimate Mastery Reasonable Initial Skepticism Wes Weimer CS 615 TR 5:00-6:15 @ OLS 005 http://www.cs.virginia.edu/~weimer/615 (note: CS 615 == CS 655) Today s Class Vague

### Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

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

### COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of

### Programmiersprachen (Programming Languages)

2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

### Compilers and computer architecture: Semantic analysis

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

### CMSC 330: Organization of Programming Languages. Lambda Calculus

CMSC 330: Organization of Programming Languages Lambda Calculus 1 Turing Completeness Turing machines are the most powerful description of computation possible They define the Turing-computable functions

### Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics

### Type Systems, Type Inference, and Polymorphism

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

### Functional Programming

Functional Programming Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Brief

### Writing Evaluators MIF08. Laure Gonnord

Writing Evaluators MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Evaluators, what for? Outline 1 Evaluators, what for? 2 Implementation Laure Gonnord (Lyon1/FST) Writing Evaluators 2 / 21 Evaluators,

### Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

### Dependant Type Systems (saying what you are) Data Abstraction (hiding what you are) Review. Dependent Types. Dependent Type Notation

Dependant Type Systems (saying what you are) Data Abstraction (hiding what you are) #1 Recount We re now reaching the point where you have all of the tools and background to understand advanced topics.

### Functional Programming. Big Picture. Design of Programming Languages

Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

### CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

### Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

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

### Functional Programming

The Meta Language (ML) and Functional Programming Daniel S. Fava danielsf@ifi.uio.no Department of informatics University of Oslo, Norway Motivation ML Demo Which programming languages are functional?

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

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

### CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

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

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