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

Size: px
Start display at page:

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

Transcription

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

2 What are dependent types? Types that depend on values of other types Used to statically enforce expressive program properties Examples: vec n type of lists of length n, static bounds checks Binary Search Tree PADS, data format invariants ASTs that enforce well-typed code CompCert compiler Types that contain computation 2

3 What about nontermination? Treatment of nontermination divides design space Affects decidability of type checking, correctness guarantees, and complexity of language Independent of type soundness Unclear impact on practicality Only total computation allowed Types restricted to total computation Examples Coq, Agda2 DML, ATS, mega, Haskell No restrictions Cayenne, Epigram, Type checking Decidable Undecidable Correctness guarantee 3 Total correctness Partial correctness 1/21/10

4 Program equivalence When types depend on programs, type equivalence depends on program equivalence Definition of program equivalence is controversial Even when the language is not Turing-complete! Many possible definitions Reduce and compare What reduction relation? (evaluation, parallel reduction, etareduction?) Type-based equivalence Behavioral equivalence Contextual equivalence Something else? 4

5 λ : Parameterized program equivalence A call-by-value language with an abstract term equivalence relation Goals for language design Simple type soundness proof based on progress and preservation Uniformity---program equivalence used by type system must be compatible with CBV What requirements for equivalence relation? Strong enough to prove type soundness Weak enough to allow desired definitions More difficult than we expected 5 1/21/10

6 "Pure everywhere" type system - PTS No syntactic distinction between types, terms, kinds e, τ, k ::= x λx.e e e' (x:τ 1 ) τ 2 One set of formation rules T C case e { C i x i e i } Γ e : τ Conversion rule uses beta-equivalence τ 1 and τ 2 are betaconvertible Γ e : τ 1 Γ τ 2 : s τ 1 τ 2 Γ e : τ 2 Term equivalence is fixed by type system (and defined to be the same as type equivalence). 6

7 λ : Parameterized program equivalence Syntactic distinction between terms, types, and kinds k ::= (x:τ) τ ::= (x:τ 1 ) τ 2 T τ e case e T e' of { C i x i τ i } e ::= x fun f (x) = e e e' C e case e of { C i x i e i } Key syntactic changes Term language includes non-termination Curry-style, no types in expressions Convenient simplifications Datatypes have one index, data constructors have one argument (unit/products in paper) No polymorphism, no higher-kinded types (future work) 7

8 Parameterized term equivalence Given an "equivalence context" Δ ::=. Δ, e 1 = e 2 Assume the existence of program equivalence predicate iseq (Δ, e 1, e 2 ) Equality is untyped No guarantee that e 1 and e 2 have the same type No assumptions about the types of the free variables Context may make unsatisfiable assumptions 8

9 Type system overview Two sorts of judgments Equality for types, contexts, and kinds Formation for contexts, kinds, types and terms Γ e : τ Typing context: Equivalence and typing assumptions Γ ::=. Γ, e 1 = e 2 Γ, x:τ Δ τ 1 τ 2 All judgments derivable from an inconsistent context incon (Δ) if there exist pure terms C i w i and C j w j such that iseq (Δ, C i w i, C j w j ) and C i C j Pure terms w ::= x fun f (x) = e C w 9

10 Type system excerpt Extract equivalence context 10

11 Questions to answer What properties of iseq must hold to show preservation & progress? What instantiations of iseq satisfy these properties? 11

12 Necessary assumptions about iseq Is an equivalence relation Preserved under contextual operations Cut: Weakening: Context Conv: Contains evaluation: e e' implies iseq (Δ, e, e') Data constructors are injective for pure arguments iseq (Δ, C w, C w' ) implies iseq (Δ, w, w') Empty context is consistent C C' implies iseq(., C w, C' w ) Closed under pure substitution iseq (Δ, e, e') implies iseq (Δ{w/x}, e{w/x}, e'{w/x}) Preservation of beta 12 1/21/10 Preservation e 1 e 2 e 1 e' 2 Transitivity of Δ τ 1 τ 2 Nat Bool Does not need to hold for arbitrary e

13 Typing rules don't use substitution Standard rule Our rule Γ e 1 : (x :τ 1 ) τ 2 Γ e 2 : τ 1 Γ e 1 e 2 : τ 2 {e 2 /x} Substitutes an arbitrary expression into the type Γ e 1 : (x:τ 1 ) τ 2 Γ e 2 : τ 1 Γ*, x e 2 τ τ 2 Γ τ : Γ e 1 e : τ 2 13 Adds assumption to the context x does not escape

14 Assumptions also for case expression Do not need a substitution to type the branches Type check scrutinee Lookup data constructors in signature Pattern variables don't escape Data type index Data constructor pattern 14

15 What satisfies the iseq properties? Compare normal forms (ignoring Δ) Only types STLC terms Contextual equivalence (ignoring Δ) Only types STLC terms RST-closure of evaluation, constructor injectivity, and equivalence assumptions CBV Contextual equivalence modulo Δ Some strange equalities that identify nonterminating terms with terminating terms Safe to conclude iseq(let x = loop in 3, 3) as long as we don t conclude iseq(let x = loop in 3, loop) Safe to say iseq(loop,3) as long as we don t say iseq(loop, 4) 15

16 What about decidable type checking? All instantiations of iseq are undecidable Must contain evaluation relation Decidable approximations are type safe, but don t satisfy preservation Any types system that checks strictly fewer terms than a safe type system is safe Preservation important for compiler transformations Want to know that inlining always produces safe code Not really an issue: Decidable doesn't mean tractable 16

17 What about termination analysis? Like most type systems, only get "partial correctness" results: Σx:t. P(x) means If this expression terminates, then it produces a value of type t such that P holds Implications (P1 P2) may be bogus Termination analysis produces total correctness Termination/stage analysis is an optimization permits proof erasure in CBV language 17

18 Future work Add polymorphism, higher-order types Keep curry-style system for simple specification of iseq Annotated external language to aid type checking Similar to ICC* [Barras and Bernardo] Terms contain type annotations, but equality defined for erased terms Type checking still undecidable but closer to an algorithm Add control/state effects to computations Should we limit domain of iseq? Non-termination ok in types, but exceptions are not? Can we provide type/termination information to strengthen equivalence? 18

19 Conclusions What have we achieved? Uniform design Same reasoning for compile time as run time Not easy for CBV! Simple design Program equivalence isolated from type system Proved all metatheory in Coq in ~2 weeks (OTT + LNgen) General design Program equivalence not nailed down Lots of examples that satisfy preservation, not just type soundness 19

20 20

21 Type equivalence for case 21

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

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

More information

Dependent Types and Program Equivalence

Dependent Types and Program Equivalence Dependent Types and Program Equivalence Limin Jia Jianzhou Zhao Vilhelm Sjöberg Stephanie Weirich Computer and Information Sciences Department, University of Pennsylvania {liminjia,jianzhou,vilhelm,sweirich}@cis.upenn.edu

More information

Dependent types and Program Equivalence

Dependent types and Program Equivalence University of Pennsylvania ScholarlyCommons Departmental Papers (CIS) Department of Computer & Information Science 1-17-2010 Dependent types and Program Equivalence Limin Jia University of Pennsylvania

More information

Programming Up-to-Congruence, Again. WG 2.8 Estes Park

Programming Up-to-Congruence, Again. WG 2.8 Estes Park Programming Up-to-Congruence, Again Stephanie Weirich University of Pennsylvania August 12, 2014 WG 2.8 Estes Park Zombie A functional programming language with a dependent type system intended for lightweight

More information

Combining Proofs and Programs in a Dependently Typed Language. Certification of High-level and Low-level Programs

Combining Proofs and Programs in a Dependently Typed Language. Certification of High-level and Low-level Programs Combining Proofs and Programs in a Dependently Typed Language Stephanie Weirich University of Pennsylvania July 7, 2014 Certification of High-level and Low-level Programs Zombie A functional programming

More information

Eta-equivalence in Core Dependent Haskell

Eta-equivalence in Core Dependent Haskell Eta-equivalence in Core Dependent Haskell You should machine-check your proofs Stephanie Weirich University of Pennsylvania Core Dependent Haskell A Specification for Dependent Types in Haskell Stephanie

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

Simple Unification-based Type Inference for GADTs

Simple Unification-based Type Inference for GADTs Simple Unification-based Type Inference for GADTs Stephanie Weirich University of Pennsylvania joint work with Dimitrios Vytiniotis, Simon Peyton Jones and Geoffrey Washburn Overview Goal: Add GADTs to

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

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

Programming Languages Lecture 15: Recursive Types & Subtyping

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)

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

Programming with Universes, Generically

Programming with Universes, Generically Programming with Universes, Generically Andres Löh Well-Typed LLP 24 January 2012 An introduction to Agda Agda Functional programming language Static types Dependent types Pure (explicit effects) Total

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

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

More information

Typing Control. Chapter Conditionals

Typing Control. Chapter Conditionals Chapter 26 Typing Control 26.1 Conditionals Let s expand our language with a conditional construct. We can use if0 like before, but for generality it s going to be more convenient to have a proper conditional

More information

Calculus of Inductive Constructions

Calculus of Inductive Constructions Calculus of Inductive Constructions Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Calculus of Inductive Constructions

More information

4.5 Pure Linear Functional Programming

4.5 Pure Linear Functional Programming 4.5 Pure Linear Functional Programming 99 4.5 Pure Linear Functional Programming The linear λ-calculus developed in the preceding sections can serve as the basis for a programming language. The step from

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

Basic Foundations of Isabelle/HOL

Basic Foundations of Isabelle/HOL Basic Foundations of Isabelle/HOL Peter Wullinger May 16th 2007 1 / 29 1 Introduction into Isabelle s HOL Why Type Theory Basic Type Syntax 2 More HOL Typed λ Calculus HOL Rules 3 Example proof 2 / 29

More information

Where is ML type inference headed?

Where is ML type inference headed? 1 Constraint solving meets local shape inference September 2005 2 Types are good A type is a concise description of the behavior of a program fragment. Typechecking provides safety or security guarantees.

More information

Part VI. Imperative Functional Programming

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

More information

Part III Chapter 15: Subtyping

Part III Chapter 15: Subtyping Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule

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

TRELLYS and Beyond: Type Systems for Advanced Functional Programming

TRELLYS and Beyond: Type Systems for Advanced Functional Programming TRELLYS and Beyond: Type Systems for Advanced Functional Programming Aaron Stump Computer Science The University of Iowa Joint work with Tim Sheard, Vilhelm Sjöberg, and Stephanie Weirich. Supported by

More information

A Specification for Dependently-Typed Haskell (Extended version)

A Specification for Dependently-Typed Haskell (Extended version) 1 A Specification for Dependently-Typed Haskell (Extended version) STEPHANIE WEIRICH, University of Pennsylvania ANTOINE VOIZARD, University of Pennsylvania PEDRO HENRIQUE AZEVEDO DE AMORIM, Ecole Polytechnique

More information

Part III. Chapter 15: Subtyping

Part III. Chapter 15: Subtyping Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule

More information

Harvard School of Engineering and Applied Sciences Computer Science 152

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

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

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

Generic Programming With Dependent Types: II

Generic Programming With Dependent Types: II Generic Programming With Dependent Types: II Generic Haskell in Agda Stephanie Weirich University of Pennsylvania March 2426, 2010 SSGIP Generic-Haskell style generic programming in Agda Dependently-typed

More information

Pattern Matching and Abstract Data Types

Pattern Matching and Abstract Data Types Pattern Matching and Abstract Data Types Tom Murphy VII 3 Dec 2002 0-0 Outline Problem Setup Views ( Views: A Way For Pattern Matching To Cohabit With Data Abstraction, Wadler, 1986) Active Patterns (

More information

Ornaments in ML. Thomas Williams, Didier Rémy. April 18, Inria - Gallium

Ornaments in ML. Thomas Williams, Didier Rémy. April 18, Inria - Gallium Ornaments in ML Thomas Williams, Didier Rémy Inria - Gallium April 18, 2017 1 Motivation Two very similar functions let rec add m n = match m with Z n S m S (add m n) let rec append ml nl = match ml with

More information

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review

More information

Typing Data. Chapter Recursive Types Declaring Recursive Types

Typing Data. Chapter Recursive Types Declaring Recursive Types Chapter 27 Typing Data 27.1 Recursive Types 27.1.1 Declaring Recursive Types We saw in the previous lecture how rec was necessary to write recursive programs. But what about defining recursive types? Recursive

More information

Inductive Definitions, continued

Inductive Definitions, continued 1 / 27 Inductive Definitions, continued Assia Mahboubi Jan 7th, 2016 2 / 27 Last lecture Introduction to Coq s inductive types: Introduction, elimination and computation rules; Twofold implementation :

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

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

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

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

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

MLW. Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. March 26, Radboud University Nijmegen

MLW. Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. March 26, Radboud University Nijmegen 1 MLW Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky Radboud University Nijmegen March 26, 2012 inductive types 2 3 inductive types = types consisting of closed terms built from constructors

More information

Tracing Ambiguity in GADT Type Inference

Tracing Ambiguity in GADT Type Inference Tracing Ambiguity in GADT Type Inference ML Workshop 2012, Copenhagen Jacques Garrigue & Didier Rémy Nagoya University / INRIA Garrigue & Rémy Tracing ambiguity 1 Generalized Algebraic Datatypes Algebraic

More information

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

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

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

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

Programming Languages Assignment #7

Programming Languages Assignment #7 Programming Languages Assignment #7 December 2, 2007 1 Introduction This assignment has 20 points total. In this assignment, you will write a type-checker for the PolyMinML language (a language that is

More information

CMSC 330: Organization of Programming Languages. Operational Semantics

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

More information

Types, Universes and Everything

Types, Universes and Everything Types, Universes and Everything Andres Löh Dept. of Information and Computing Sciences, Utrecht University P.O. Box 80.089, 3508 TB Utrecht, The Netherlands Web pages: http://www.cs.uu.nl/wiki/center May

More information

Alonzo a Compiler for Agda

Alonzo a Compiler for Agda Alonzo a Compiler for Agda Marcin Benke Institute of Informatics, Warsaw University, ben@mimuw.edu.pl 1 Introduction Agda [Norell, 2007] is an interactive system for developing constructive proofs in a

More information

Static and User-Extensible Proof Checking. Antonis Stampoulis Zhong Shao Yale University POPL 2012

Static and User-Extensible Proof Checking. Antonis Stampoulis Zhong Shao Yale University POPL 2012 Static and User-Extensible Proof Checking Antonis Stampoulis Zhong Shao Yale University POPL 2012 Proof assistants are becoming popular in our community CompCert [Leroy et al.] sel4 [Klein et al.] Four-color

More information

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015 TYPE INFERENCE François Pottier The Programming Languages Mentoring Workshop @ ICFP August 30, 2015 What is type inference? What is the type of this OCaml function? let f verbose msg = if verbose then

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Combining Programming with Theorem Proving

Combining Programming with Theorem Proving Combining Programming with Theorem Proving Chiyan Chen and Hongwei Xi Boston University Programming with Theorem Proving p.1/27 Motivation for the Research To support advanced type systems for practical

More information

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::

More information

The Polymorphic Blame Calculus and Parametricity

The Polymorphic Blame Calculus and Parametricity 1 / 31 The Polymorphic Blame Calculus and Parametricity Jeremy G. Siek Indiana University, Bloomington University of Strathclyde August 2015 2 / 31 Integrating static and dynamic typing Static Dynamic

More information

Lecture 8: Summary of Haskell course + Type Level Programming

Lecture 8: Summary of Haskell course + Type Level Programming Lecture 8: Summary of Haskell course + Type Level Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 31, 2017 Principles from Haskell

More information

Writing code that I'm not smart enough to write. A funny thing happened at Lambda Jam

Writing code that I'm not smart enough to write. A funny thing happened at Lambda Jam Writing code that I'm not smart enough to write A funny thing happened at Lambda Jam Background "Let s make a lambda calculator" Rúnar Bjarnason Task: write an interpreter for the lambda calculus Lambda

More information

On the Logical Foundations of Staged Computation

On the Logical Foundations of Staged Computation On the Logical Foundations of Staged Computation Frank Pfenning PEPM 00, Boston, MA January 22, 2000 1. Introduction 2. Judgments and Propositions 3. Intensional Types 4. Run-Time Code Generation 5. The

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

Lecture 5: The Untyped λ-calculus

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,

More information

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Toby Murray, June Andronick, Gerwin Klein λ 1 Last time... λ calculus syntax free variables, substitution β reduction α and η conversion

More 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

Symmetry in Type Theory

Symmetry in Type Theory Google May 29th, 2012 What is Symmetry? Definition Symmetry: Two or more things that initially look distinct, may actually be instances of a more general underlying principle. Why do we care? Simplicity.

More information

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

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

More information

CSE-321 Programming Languages 2010 Final

CSE-321 Programming Languages 2010 Final Name: Hemos ID: CSE-321 Programming Languages 2010 Final Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 18 28 16 12 36 40 150 There are six problems on 16 pages, including two work sheets, in

More information

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

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

More information

Universes. Universes for Data. Peter Morris. University of Nottingham. November 12, 2009

Universes. Universes for Data. Peter Morris. University of Nottingham. November 12, 2009 for Data Peter Morris University of Nottingham November 12, 2009 Introduction Outline 1 Introduction What is DTP? Data Types in DTP Schemas for Inductive Families 2 of Data Inductive Types Inductive Families

More information

Combining Proofs and Programs in a Dependently Typed Language

Combining Proofs and Programs in a Dependently Typed Language University of Pennsylvania ScholarlyCommons Technical Reports (CIS) Department of Computer & Information Science 1-1-2013 Combining Proofs and Programs in a Dependently Typed Language Stephanie Weirich

More information

A Canonical 1 Locally Named Representation of Binding. α -equivalence is identity. Randy Pollack. Masahiko Sato. LFCS, University of Edinburgh

A Canonical 1 Locally Named Representation of Binding. α -equivalence is identity. Randy Pollack. Masahiko Sato. LFCS, University of Edinburgh A Canonical 1 Locally Named Representation of Binding Randy Pollack LFCS, University of Edinburgh Masahiko Sato Graduate School of Informatics, Kyoto University Version of December 7, 2009 1 α -equivalence

More information

Arbitrary-rank polymorphism in (GHC) Haskell

Arbitrary-rank polymorphism in (GHC) Haskell Arbitrary-rank polymorphism in (GHC) Haskell CAS 743 Stephen Forrest 20 March 2006 Damas-Milner Type System A Damas-Milner type system (also called Hindley-Milner) is a traditional type system for functional

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

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

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

Type- & Example-Driven Program Synthesis. Steve Zdancewic WG 2.8, August 2014

Type- & Example-Driven Program Synthesis. Steve Zdancewic WG 2.8, August 2014 Type- & Example-Driven Program Synthesis Steve Zdancewic WG 2.8, August 2014 Joint work with Peter-Michael Osera CAVEATS Work in progress Similar work been done before This is our attempt to understand

More information

Flang typechecker Due: February 27, 2015

Flang typechecker Due: February 27, 2015 CMSC 22610 Winter 2015 Implementation of Computer Languages I Flang typechecker Due: February 27, 2015 Project 3 February 9, 2015 1 Introduction The third project is to implement a type checker for Flang,

More information

Lecture #23: Conversion and Type Inference

Lecture #23: Conversion and Type Inference Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:

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

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = Hello; Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";

More information

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

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

More information

Programming with Types

Programming with Types Programming with Types Run-time type analysis and the foundations of program reflection Stephanie Weirich Cornell University Reflection A style of programming that supports the run-time discovery of program

More information

λ calculus is inconsistent

λ calculus is inconsistent Content Rough timeline COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Toby Murray λ Intro & motivation, getting started [1] Foundations & Principles

More information

CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

More information

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

n   n Try tutorial on front page to get started! n   spring13/ n Stack Overflow! Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!

More information

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

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

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

Costly software bugs that could have been averted with type checking

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

More information

Abstraction Elimination for Kappa Calculus

Abstraction Elimination for Kappa Calculus Abstraction Elimination for Kappa Calculus Adam Megacz megacz@cs.berkeley.edu 9.Nov.2011 1 Outline Overview: the problem and solution in broad strokes Detail: kappa calculus and abstraction elimination

More information

Recursive Types and Subtyping

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

More information

Equational Reasoning about Programs with General Recursion and Call-by-value Semantics

Equational Reasoning about Programs with General Recursion and Call-by-value Semantics University of Pennsylvania ScholarlyCommons Departmental Papers (CIS) Department of Computer & Information Science 1-24-2012 Equational Reasoning about Programs with General Recursion and Call-by-value

More information

Second-Order Type Systems

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

More information

AURA: A programming language for authorization and audit

AURA: A programming language for authorization and audit AURA: A programming language for authorization and audit Jeff Vaughan Limin Jia, Karl Mazurak, Jianzhou Zhao, Luke Zarko, Joseph Schorr, and Steve Zdancewic Department of Computer and Information Science

More information

Recursive Types and Subtyping

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

More information

Automated Reasoning. Natural Deduction in First-Order Logic

Automated Reasoning. Natural Deduction in First-Order Logic Automated Reasoning Natural Deduction in First-Order Logic Jacques Fleuriot Automated Reasoning Lecture 4, page 1 Problem Consider the following problem: Every person has a heart. George Bush is a person.

More information

The Typed λ Calculus and Type Inferencing in ML

The Typed λ Calculus and Type Inferencing in ML Notes on Types S. Arun-Kumar Department of Computer Science and Engineering Indian Institute of Technology New Delhi, 110016 email: sak@cse.iitd.ernet.in April 14, 2002 2 Chapter 1 The Typed λ Calculus

More information

Isabelle s meta-logic. p.1

Isabelle s meta-logic. p.1 Isabelle s meta-logic p.1 Basic constructs Implication = (==>) For separating premises and conclusion of theorems p.2 Basic constructs Implication = (==>) For separating premises and conclusion of theorems

More information

Meta-programming with Names and Necessity p.1

Meta-programming with Names and Necessity p.1 Meta-programming with Names and Necessity Aleksandar Nanevski Carnegie Mellon University ICFP, Pittsburgh, 05 October 2002 Meta-programming with Names and Necessity p.1 Meta-programming Manipulation of

More information

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop AXIOMS OF AN IMPERATIVE LANGUAGE We will use the same language, with the same abstract syntax that we used for operational semantics. However, we will only be concerned with the commands, since the language

More information

Semantic Subtyping with an SMT Solver

Semantic Subtyping with an SMT Solver Semantic Subtyping with an SMT Solver Cătălin Hrițcu, Saarland University, Saarbrücken, Germany Joint work with Andy Gordon, Gavin Bierman, and Dave Langworthy (all from Microsoft) Refinement Types + Type-test

More information

From Types to Sets in Isabelle/HOL

From Types to Sets in Isabelle/HOL From Types to Sets in Isabelle/HOL Extented Abstract Ondřej Kunčar 1 and Andrei Popescu 1,2 1 Fakultät für Informatik, Technische Universität München, Germany 2 Institute of Mathematics Simion Stoilow

More information