Lecture 9 : Universal Types

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 15 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Functional Programming Lecture 13 - induction on lists.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Proofs and Programs Wei Hu 11/01/2007. Outline  Motivation  Theory  Lambda calculus  Curry-Howard Isomorphism  Dependent types  Practice  Coq Wei.
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
1 PROPERTIES OF A TYPE ABSTRACT INTERPRETATER. 2 MOTIVATION OF THE EXPERIMENT § a well understood case l type inference in functional programming à la.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
CSE-321 Programming Languages Predicative Polymorphic -Calculus POSTECH May 23, 2007 박성우.
5/10/20151 GC16/3011 Functional Programming Lecture 13 Example Programs 1. Evaluating arithmetic expressions 2. lists as functions.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from G. Klein, NICTA.
CS 611 Advanced Programming Languages Andrew Myers Cornell University Lecture 27 Type inference 2 Nov 05.
CS5371 Theory of Computation
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Catriel Beeri Pls/Winter 2004/05 types 65  A type-checking algorithm The task: (since we start with empty H, why is the goal not just E?) The rule set.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
Computability and Complexity 10-1 Computability and Complexity Andrei Bulatov Gödel’s Incompleteness Theorem.
Semantics for MinML COS 441 Princeton University Fall 2004.
CS5371 Theory of Computation Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)
Algorithms: Selected Exercises Goals Introduce the concept & basic properties of an algorithm.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
Lesson 4 Typed Arithmetic Typed Lambda Calculus 1/21/02 Chapters 8, 9, 10.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Universal Types Report by Matthias Horbach. Contents Types of Polymorphism System F Basic Properties Erasure Impredicativity Parametricity.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Advanced Formal Methods Lecture 4: Isabelle – Types and Terms Mads Dam KTH/CSC Course 2D1453, Some material from Paulson.
Kyung-Goo Doh Hanyang University - ERICAComputer Science & Engineering Functional Programming / Imperative Programming CSE215 Fundamentals of Program Design.
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
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.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CSE Winter 2008 Introduction to Program Verification February 5 calculating with simplify.
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
1 Interactive Computer Theorem Proving CS294-9 October 19, 2006 Adam Chlipala UC Berkeley Lecture 9: Beyond Primitive Recursion.
1 Interactive Computer Theorem Proving CS294-9 September 7, 2006 Adam Chlipala UC Berkeley Lecture 3: Data structures and Induction.
Lesson 10 Type Reconstruction
CS5205: Foundation in Programming Languages Type Reconstruction
Generic Programming and Proving for Programming Language Metatheory
Lecture 11: Proof by Reflection
Lesson 5 Simple extensions of the typed lambda calculus
CS5205: Foundations in Programming Languages
Functional Programming
Programming Languages and Compilers (CS 421)
CSE-321 Programming Languages Simply Typed -Calculus
ML: a quasi-functional language with strong typing
Propositional Calculus: Boolean Functions and Expressions
A lightening tour in 45 minutes
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
CS154, Lecture 11: Self Reference, Foundation of Mathematics
Lesson 4 Typed Arithmetic Typed Lambda Calculus
6.001 SICP Data abstractions
Busch Complexity Lectures: Undecidable Problems (unsolvable problems)
Propositional Calculus: Boolean Algebra and Simplification
Typed Arithmetic Expressions
Simplification of Boolean Expressions
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Recursion and Fixed-Point Theory
CS154, Lecture 11: Self Reference, Foundation of Mathematics
CSE S. Tanimoto Lambda Calculus
Lecture 15: Crazy Eddie and the Fixed Points Background
Presentation transcript:

Lecture 9 : Universal Types CS5205: Foundation in Programming Languages Lecture 9 : Universal Types Motivation for Universal Types System F & Examples Properties Type Reconstruction & Parametricity CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Motivation for Universal Types Lack of code reuse! Example: doubleNat = l f: Nat ! Nat. l x:Nat. f ( f (x) ) doubleBool = l f: Bool ! Bool. l x:Bool. f ( f (x) ) doubleFun = l f: (Nat ! Nat) ! (Nat ! Nat). l x: Nat ! Nat. f ( f (x) ) CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Properties of Let Polymorphism allows for easy type reconstruction restricted to the let construct problems with references (restricted to values on the RHS of =). CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Idea of Universal Types Abstract over type! double = l X. l f: X ! X. l x:X. f (f (x)) > double : 8 X. (X ! X) ! X ! X double [Nat] > <fun> : (Nat ! Nat) ! Nat ! Nat double [Bool] > <fun> : (Bool ! Bool) ! Bool ! Bool CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Evaluation (Type Abstraction/Application) t1 ! t1’ t1[T2] ! t1’ [T2] (E-TApp) (E-TAppTAbs) (l X. t) [T] ! [X a T] t CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Typing (Type Abstraction/Application) , X ` t : T  ` l X . t : 8 X. T (T-TAbs)  ` t1 : 8 X. T1  ` t1[T2] : [X a T2] T1 (T-TApp) CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Example : Identity Function Creating the polymorphic identity function: id = l X. l x:X. x > id : 8 X. X ! X Using the polymorphic identity function: id [Nat] > <fun> : Nat ! Nat id [Bool] true > true : Bool CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Example : Self-Application We can apply a function to itself (in System F). Define selfApp = l x: 8 X. X ! X . (x [8 X. X ! X ]) x > selfApp : (8 X. X ! X) ! (8 X. X ! X) One use of self-application is: quadruple = selfApp double > quadruple : 8 X. (X ! X) ! (X ! X) Exercise : show that above is the same as: quadruple = l X. double [X ! X] (double [X]) CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Example : Polymorphic List Assume that type constructor List is given with the following primitives: nil : 8 X. List X cons : 8 X. X ! List X ! List X isnil : 8 X. List X ! Bool head : 8 X. List X ! X tail : 8 X. List X ! List X CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Example : Map With the help of fix, we can write a polymorphic map operation, as follows: map = l X. l Y. l f: X ! Y. fix (l m: (List X) ! (List Y). l l:List X. if isnil [X] l then nil [Y] else cons [Y] (f (head [X] l)) (m (tail [X] l))) ) > map : 8 X. 8 Y. (X ! Y) ! List X ! List Y CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types System F : Soundness Properties Preservation Theorem: If  ` t : T and t ! t’ then  ` t’ : T Progress Theorem If t is a closed well-typed term, then either t is a value or else there is some t’ with t ! t’. CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types System F : Normalisation A term is normalizing if there is no infinite evaluation t ! t1 ! t2 ! t3 ! … Well-typed System F terms (without the fix-point operator) are normalizing. CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types System F : Historical Background Discovered by Jean-Yves Girard in 1972 for proof theory. Independently developed by John Reynolds 1974 as polymorphic lambda calculus. Normalization : quite innovative inductive proof technique due to Tait (1968) and Girard (1972). Type reconstruction : was open problem until 1994! CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Undecidability of Type Reconstruction for System F. Wells 1994 : it is undecidable when given a closed term m of the untyped lambda calculus, if there is some well-typed term t in System F such that erase(t)=m. The type erasure operation is defined as: erase(x) = x erase(l x:T. t) = l x. erase(t) erase(t1 t2) = erase(t1) erase(t2) erase(l X. t) = erase(t) erase(t [T] ) = erase(t) CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types What to do with Undecidability? Restrict the language : let polymorphism of ML, rank-2 polymorphism, etc. Partial Type Reconstruction: correct but incomplete approaches such as local type inference, greedy type inference, etc. CS5205 Lecture 9 : Universal Types

Lecture 9 : Universal Types Parametricity Polymorphic programs operate uniformly over any input, independently of their type. Language implementations benefit from this parametricity by generating only one machine code version for polymorphic functions. Also, certain theorems come for free. At runtime, type application does not result in any computation. This is exemplified by OCaml’s let polymorphism, where no type application is needed. CS5205 Lecture 9 : Universal Types