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
#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 #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
#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
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
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 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our
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
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,
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
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 Lecture 7: Simple Types and Simply-Typed Lambda Calculus Prof. Liang Huang email@example.com 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 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 #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
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 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
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 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
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 #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
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
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
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
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
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
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 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 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
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
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 Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol
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 Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions
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 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 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
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
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
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
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 Lecture 1 - Introduction Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014
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
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 #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:
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
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
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 Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Use currying
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
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 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
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 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 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.
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 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,
CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation
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 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 Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics
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 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
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) #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 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 Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:
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
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
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.......................
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.
Lecture Outline Operational Semantics of Cool COOL operational semantics Motivation Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Notation The rules CS781(Prasad) L24CG 1 CS781(Prasad)
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 Statically vs. Dynamically typed languages