Strict Bidirectional Type Checking Adam Chlipala, Leaf Petersen, and Robert Harper.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 4 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Querying Workflow Provenance Susan B. Davidson University of Pennsylvania Joint work with Zhuowei Bao, Xiaocheng Huang and Tova Milo.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
Main Index Contents 11 Main Index Contents Week 10 – Recursive Algorithms.
A Type System for Well-Founded Recursion Derek Dreyer Carnegie Mellon University POPL 2004 Venice, Italy.
A Type Theory for Memory Allocation and Data Layout Leaf Petersen, Robert Harper, Karl Crary and Frank Pfenning Carnegie Mellon.
Principal Type Schemes for Modular Programs Derek Dreyer and Matthias Blume Toyota Technological Institute at Chicago ESOP 2007 Braga, Portugal.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
A Concurrent Logical Framework (Joint work with Frank Pfenning, David Walker, and Kevin Watkins) Iliano Cervesato ITT Industries,
Tirgul 10 Rehearsal about Universal Hashing Solving two problems from theoretical exercises: –T2 q. 1 –T3 q. 2.
1 A Dependently Typed Assembly Language Hongwei Xi University of Cincinnati and Robert Harper Carnegie Mellon University.
Computability and Complexity 32-1 Computability and Complexity Andrei Bulatov Boolean Circuits.
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Logical Properties of CPS Transforms Deepak Garg Fall, 2004.
Catriel Beeri Pls/Winter 2004/5 inductive-revisited 1 Inductive definitions revisited  Generated and Freely generated sets oPattern match, unification.
Gradient Methods Yaron Lipman May Preview Background Steepest Descent Conjugate Gradient.
Semantics for MinML COS 441 Princeton University Fall 2004.
Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.
CS Bayesian Learning1 Bayesian Learning. CS Bayesian Learning2 States, causes, hypotheses. Observations, effect, data. We need to reconcile.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
LIAL HORNSBY SCHNEIDER
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Week 3 Part I Kyle Dewey. Overview Odds & Ends Constants Errors Functions Expressions versus statements.
Lecture 8. How to Form Recursive relations 1. Recap Asymptotic analysis helps to highlight the order of growth of functions to compare algorithms Common.
Benjamin Gamble. What is Time?  Can mean many different things to a computer Dynamic Equation Variable System State 2.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 3 Polynomial and Rational Functions Copyright © 2013, 2009, 2005 Pearson Education, Inc.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
A Type System for Borrowing Permissions Karl Naden, Rob Bocchino Jonathan Aldrich, Kevin Bierhoff POPL – January 27, 2012 School of Computer Science.
Verification & Validation By: Amir Masoud Gharehbaghi
Mechanizing Metatheory without Typing Contexts TYPES 2011 September 10, 2011 Jonghyun Park, Jeongbong Seo, Sungwoo Park, Gyesik Lee* Pohang University.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Zero of Polynomial Functions Factor Theorem Rational Zeros Theorem Number of Zeros Conjugate Zeros Theorem Finding Zeros of a Polynomial Function.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Functional Programming
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Lecture 2 Introduction to Programming
Java Programming Loops
Problem Solving Skill Area 305.1
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Java Programming Loops
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Decidability continued….
Global Challenge Love Heart Lesson 3.
The Selection Problem.
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Presentation transcript:

Strict Bidirectional Type Checking Adam Chlipala, Leaf Petersen, and Robert Harper

1/10/052 Type Systems Less Type Annotation More Type Annotation ML Concise syntax. Compact representation. Complex (global) type reconstruction problem. Undecidable past a certain point. Verbose syntax. Representation issues. Simple or no type reconstruction. Powerful type systems are still decidable. Haskell Java TILT IL

1/10/053 Type Systems Less Annotation More Annotation ML Concise (enough) syntax. Compact representation. Simple syntax directed typechecking. Powerful and decidable type systems. Haskell Java TILT IL Pierce, Turner (POPL ‘98)

1/10/054 Simply Typed Calculus

1/10/055 TermsTypes 10

1/10/056 TermsTypes 10 23

1/10/057 TermsTypes

1/10/058 TermsTypes

1/10/059 TermsTypes …… ii 2 -1 Quadratic! 

1/10/0510 Algorithmic view Inputs are black. Outputs are red.

1/10/0511 Algorithmic view Inputs are black. Outputs are red. Redundant

1/10/0512 Algorithmic view Inputs are black. Outputs are red.

1/10/0513 Algorithmic view Inputs are black. Outputs are red. Redundant

1/10/0514 Bidirectional Typechecking Synthesis: Typed terms. Analysis: Checkable terms.

1/10/0515 TermsTypes 11

1/10/0516 TermsTypes 11 23

1/10/0517 TermsTypes

1/10/0518 TermsTypes

1/10/0519 TermsTypes …… i2i-1 Linear!

1/10/0520 Unnecessary! Much simpler technique works fine. Good asymptotic behavior. Syntax directed. Extends directly to sum types.

1/10/0521 Recursive types.

1/10/0522 Simple term

1/10/0523

1/10/0524 Fold Annotations Only

1/10/0525 With Sum Annotations

1/10/0526 Bidirectional version

1/10/0527 Let Binding Surprisingly, bidirectional typechecking interacts badly with let binding. –Quadratic increase in annotation size in bad cases. Bad - programmers use let. Bad - compilers use let. –Put code in “named form” (sequentialization)

1/10/0528 Binding forms Analysis binding: Synthesis binding:

1/10/0529

1/10/0530

1/10/0531

1/10/0532 Sequentializing bidirectional terms may lead to quadratic increase in type size! 

1/10/0533 Binding forms (revisited) Analysis binding: – Synthesis binding: – Undecorated analysis binding? – –Might solve our problem.

1/10/0534

1/10/0535

1/10/0536

1/10/0537 Can we typecheck it?

1/10/0538

1/10/0539

1/10/0540

1/10/0541

1/10/0542 Key points: Typecheck body first. Context of occurrence gives a unique type to z 0 because it occurs in an analysis position.

1/10/0543 Algorithmically Speaking Divide context into input and output zones. Input zone variables must declare types. –Explicitly: –Implicitly: Output zone variables get types from occurrences: – –Check A after getting type for u from E. –Must ensure variables actually occur!!

1/10/0544 Formally Look to strict logic –Substructural logic in which hypotheses must be used at least once. Normal variables in unrestricted context (  may occur zero or more times. Strict variables in restricted context (  must occur at least once. Contrast with linear logic: –Linear variables in restricted context (  ) must occur exactly once.

1/10/0545 Strict Bidirectional Typechecking Judgments: –Analysis: –Synthesis: Unrestricted context (  is input mapping variables to their types. Restricted context (  is output mapping variables to their types. Strict variables must occur in analysis positions.

1/10/0546 Cool Fact #1 Theorem: The strict bidirectional typechecking rules constitute an algorithm. –Syntax directed. –Uniquely determined outputs. –Proof is in paper.

1/10/0547 Cool Fact #2 Theorem: Sequentialization into the strict language never increases type size. –Size of sequentialized form is bounded above by the size of the original. –Proof is in paper.

1/10/0548 Recap Bidirectional representation yields asymptotic improvements in type size. Let binding destroys these benefits. Recognizing strictness allows benefits to be recaptured without unification.

1/10/0549 The End