Types and Programming Languages. Lecture 8. Recursive type
|
|
- Katrina Houston
- 5 years ago
- Views:
Transcription
1 Types and Programming Languages Lecture 8. Recursive type Xiaojuan Cai BASICS Lab, Shanghai Jiao Tong University Fall, 2016
2 List[T] List[T] is a type constructor whose elements are lists with elements of type T. A list is either null or else a pair (cons cell) of an element and another list. Similar structures include: queues, binary trees, etc. We need a general mechanism with which they can be defined from simpler elements. This mechanism is called recursive types. The system studied in this lecture is simply typed λ-calculus with recursive types. And we will only focus on NatList. Another mechanism for List[T] is type operator (Chapter 29).
3 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
4 Recursive types How to define the type NatList? It s a variant type: NatList =< nil : Unit, cons : {Nat,...} > The... is another list of number! NatList =< nil : Unit, cons : {Nat, NatList} > Above definition will introduce divergence. Like recursive functions, we introduce an explicit recursion operator µ for types: NatList = µx. < nil : Unit, cons : {Nat, X} >
5 NatList operations Recall in Figure 11-13, we define lots of operations for List[T] as built-in. Here we will define them as functions. nil = <nil = unit> as NatList; cons = λn:nat.λl:natlist.<cons = {n,l}> as NatList; isnil = λl : NatList. case l of < nil = u > true < cons = p > false hd = λl : NatList. case l of < nil = u > 0 < cons = p > p.1 tl = λl : NatList. case l of < nil = u > 0 < cons = p > p.2
6 NatList functions sumlist = fix (λs : NatList Nat. λl : NatList. case l of < nil = u > 0 < cons = p > plus p.1 (s p.2)) mylist = cons 2 (cons 3 (cons 5 nil)) sumlist mylist returns 10.
7 Hungry functions Hungry = µa.nat-> A f = fix (λf:hungry.λn:nat.f) f ;
8 Streams Stream is the type of functions that can produce an arbitrary number of numbers (or other types). Stream = µa. Unit->{Nat,A} hd = λs:stream.(s unit).1; tl = λs:stream.(s unit).2; But how to define a stream? upfrom0 = fix (λf:nat->stream.λn:nat.λ :Unit.{n,f (succ n)}) 0; hd upfrom0 returns 0. hd (tl (tl (tl upfrom0))) returns 3. Quiz. Define a stream that yields all the elements to be 1. ones = fix (λs:stream.λ :Unit.{1,s})
9 Processes Processes are functions that accept a number and return a number and a new process. Process = µa. Nat->{Nat,A} p = fix (λf:nat->process.λacc.λn:nat. let newacc = plus acc n in {newacc,f newacc}) 0; curr = λs:process.(s 0).1 send = λn:nat.λs:process.(s n).2 curr (send 20 (send 3 (send 5 p))) returns 28.
10 Objects Processes are similar to objects which interacting with data. Counter = µc.{get:nat, inc:unit->c} c = let create = fix in create {x=0} (λf:{x:nat}->counter.λs:{x:nat}. {get = s.x, inc = λ :Unit.f {x=succ(s.x)}) c1 = c.inc unit; c2 = c1.inc unit; c2.get;
11 Recursive values from recursive types A more surprising use of recursive types is a well-typed implementation of the fixed-point combinator. Quiz. Please rewrite the fix-point operator into simply typed λ-term with recursive type. fix = λf.(λx.f(x x))(λx.f(x x)) fix T = λf : T T.(λx : (µa.a T).f (x x)) (λx : (µa.a T).f (x x); Recursive types break the strong normalization property: diverge T = λ : Unit.fix T (λx : T.x) This reveals the expressive power of recursive types.
12 Untyped λ-calculus Moreover, we can embed the whole untyped λ-calculus into a statically typed language with recursive types. D = µx.x->x lam = λf:d->d.f as D ap = λf:d.λa:d.f a Here comes the encoding from untyped λ-calculus into a well-typed one: x = x λx.m = lam (λx : D. M ) M N = ap M N
13 Untyped λ-calculus with other features If we extend untyped λ-calculus with numbers, then the whole datatype is extended to be a variant type. D = µx.<nat:nat, fn:x->x> ap = λf:d.λa:d.case f of <nat=n> diverge D <fn = f> f a unit
14 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
15 Formalities There are two basic approaches to recursive types. The essential difference is their reponse to the question: What is the relation between the type µx.t and its one-step unfolding? For example, NatList and <nil:unit, cons:{nat,natlist}>. The equi-recursive approach takes these two expressions definitionally equal interchangeable in any context. The iso-recursive approach takes these two expression different, but isomorphic.
16 Equi-recursive Pros: More intuitive; Match with all the previous presentations. Definitions, safety theorems and even proofs remains unchanged. Cons: The implementation requires some work, Since type checking can not work directly with infinite structures. (Chapter 21) Interactions with other advanced features, such as quantification, lead to theoretical difficulties, even undecidability.
17 Iso-recursive The unfolding of µx.t is using the standard notation for substitution: unfolds to NatList = µx. < nil : Unit, cons : {Nat, X} > < nil : Unit, cons : {Nat, µx. < nil : Unit, cons : {Nat, X} >} > We need to introduce fold[µx.t] and unfold[µx.t] explicitly into syntax.
18 Iso-recursive: pros and cons Pros: Less work for type systems. Easy to interact with other features. Cons: Heavier: requiring programs to be decorated with fold and unfold. Iso-recursive is quite palatable in practice. Since the fold and unfold notations can be hidden by coalescing them with other annotations. Each use of constructors is to build a value with implicitly include a fold; Each use of case implicitly forces an unfold.
19 Subtyping Assume Even is a subtype of Nat. What the relation between these two types? µx.nat (Even X) and µx.even (Nat X)
20 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
21 Coming soon We will develop the theoretical foundations of typecheckers for equi-recursive types. We will deal with a system including both recursive types and subtyping. We will use coinduction to make equi-recursive types precise.
22 Induction and coinduction Let s fix some universal set U, which denotes everything in the world. Definition. A function F P(U) P(U) is monotone if X Y implies F (X ) F (Y ), where P(U) is the powerset of U. In the following, F is always monotone, also called as generating function. Definition. Let X be a subset of U. X is F -closed if F (X ) X. X is F -consistent if X F (X ). X is a fixed point if X = F (X ).
23 Example Consider the three-element universe U = {a, b, c}: E 1 ( ) = {c} E 1 ({a, b}) = {c} E 1 ({a}) = {c} E 1 ({a, c}) = {b, c} E 1 ({b}) = {c} E 1 ({b, c}) = {a, b, c} E 1 ({c}) = {b, c} E 1 ({a, b, c}) = {a, b, c} {a, b, c} is E 1 -closed;, {c}, {b, c} and {a, b, c} are E 1 -consistent; {a, b, c} is a fixed point of E 1. Actually, E 1 can be represented as a set of inference rules: c c b b c a
24 Knaster-Tarski theorem Theorem [Knaster-Tarski]. The intersection of all F -closed sets is the least fixed point of F, denoted µf ; The union of all F -consistent sets is the greatest fixed point of F, denoted νf. Example. (continued) µe 1 = νe 1 = {a, b, c}. Corollary. Principle of induction: If X is F -closed, then µf X ; Principle of coinduction: If X is F -consistent, then X νf ;
25 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
26 Finite and infinite types Definition. A tree type is a partial function T {1, 2} {,, Top} satisfying: T ( ) is defined; if T (π, σ) is defined then T (π) is defined; if T (π) = or T (π) =, then T (π, 1) and T (π, 2) are defined; if T (π) = Top, then T (π, 1) and T (π, 2) are undefined;
27 An alternative definition for finite tree types A tree type T is finite if dom(t ) is finite. The set of finite tree types can be defined more compactly by a grammar: T ::= Top T T T T The set of all finite tree types is the least fixed point of the generating function described by the grammar. The set of all tree types is the greatest fixed point of the generating function described by the grammar.
28 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
29 Subtyping for finite types Definition Two finite tree types S and T are in the subtype relation if (S, T ) µs f, where the monotone function S f P(T f T f ) P(T f T f ) is defined by S f (R) = {(T, Top) T T f } {(S 1 S 2, T 1 T 2 ) (S 1, T 1 ), (S 2, T 2 ) R} {(S 1 S 2, T 1 T 2 ) (T 1, S 1 ), (S 2, T 2 ) R}. Quiz. Give a set of inference rules that precisely capture the function above.
30 Subtyping for infinite types Definition Two tree types S and T are in the subtype relation if (S, T ) νs, where the monotone function S P(T T ) P(T T ) is defined by Quiz. S(R) = {(T, Top) T T } {(S 1 S 2, T 1 T 2 ) (S 1, T 1 ), (S 2, T 2 ) R} {(S 1 S 2, T 1 T 2 ) (T 1, S 1 ), (S 2, T 2 ) R}. Check that νs is not the whole of T T.
31 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
32 Membership checking How to decide, given a generating function F on some universe U and an element x U, whether or not x νf? An element x may generated from some set X such that x F (X ). We call X the generating set for x. There are minimal generating set for x. We will furthur focus on the class of invertible functions, where each x has at most one minimal generating set.
33 Invertible generating functions Definition. A generating function F is said to be invertible if, for all x U, the collection of sets G x = {X U x F (X )} either is empty or contains a unique member that is a subset of all the others. Definition. If F is invertible, the partial function support F U P(U) is defined as follows: { X if X Gx and X support F (x) = G x.x X if G x = Which can be lifted to sets: { support F (X ) = x X support F (x) if x X.support F (x) o.w.
34 Towards an algorithm An element x is F -supported if support F (x) ; Otherwise, x is F -unsupported. An F -supported element is called F -ground if support F (x) =. An invertible function can be visualized as a support graph. Quiz. Give the inference rules for this function E.
35 gfp F funciton Definition. Suppose F is an invertible generating function. Define the boolean valued function gfp F (or just gfp) as follows: gfp(x ) = if support(x ), then false else if support(x ) X, then true else gfp(support(x ) X ). If gfp(x) = gfp({x}) returns true, then x νf ; If it returns false, x νf. The remainder of this part is devoted to proving the correctness and termination of gfp.
36 Correctness Lemma X F (Y ) iff support F (X ) and support F (X ) Y. Lemma Suppose P is a fixed point of F. Then X P iff support F (X ) and support F (X ) P. Theorem If gfp(x ) = true, then X νf ; If gfp(x ) = false, then X νf ;
37 Termination Given an invertible generating function F, and an element x U: { if support(x) pred(x) = support(x) if support(x) pred(x ) = x X pred(x). reachable(x ) = n 0 pred n (X ). F is finite state if reachable(x) is finite for any x U. Theorem if reachable(x ) is finite, then gfp(x ) terminates for any finite X U.
38 Coming soon We have algorithms for checking membership of νf for some invertible and finite state generating function F. Now we will consider our subtyping function S, which is invertible but may not be finite state. We will show that the algorithms always terminate for regular type trees.
39 Subtrees Definition. A tree type S is a subtree of a tree type T if S = λσ.t (π, σ) for some π. Definition. A tree type T T is regular if subtrees(t ) is finite, i.e., if T has finitely many distinct subtrees. The set of regular tree types is written T r.
40 Examples Every finite tree type is regular, for example, T = Top->(Top Top); Some infinite tree types are regular, for example, T = Top (Top (Top...)); Some infinite tree types are irregular, for example, T=B (A (B (A (A (B (A (A (A (B...))))))))) Proposition. The restriction S r of generating function S on T r is finite state.
41 Outline Recursive types Formalities Metatheory of recursive types Induction and coinduction Finite and infinite types Subtyping Membership checking Regular trees µ-types
42 µ-types The set of raw µ-types can be defined by this grammar: T ::= X Top T T T T µx.t Not all the raw µ-types can be reasonably interpreted as representations of tree types, for example µx.x. Definition. A raw µ-type T is contractive if, for any subexpression of T of the form µx.µx 1.µX 2...µX n.s the body S is not X. µ-types are contractive raw µ-types. The set of µ-types are denoted as T m. We write µ-height(t ) for number of µ-bindings at the front of T.
43 From µ-types to tree types Definition. The function treeof, mapping closed µ-types to tree types, is defined inductively as follows: treeof(top)( ) = Top treeof(t 1 T 2 )( ) = treeof(t 1 T 2 )(i, π) = treeof(t i )(π) treeof(t 1 T2)( ) = treeof(t 1 T 2 )(i, π) = treeof(t i )(π) treeof(µx.t)(π) = treeof([x µx.t]t)(π) Example. What is treeof (µx.((x Top) X)). Every recursive use of treeof on the right-hand side reduces the lexicographic size of the pair ( π, µ-height(t )); All recursive calls preserve contractiveness and closure of the argument types.
44 Subtyping for µ-types S <: [X µx.t]t S <: µx.t [X µx.s]s <: T µx.s <: T We modify the subtyping generation function from S to S m. Definition Two finite tree types S and T are in the subtype relation if (S, T ) νs m, where the monotone function S m P(T m T ) P(T m T m ) is defined by S m (R) = {(T, Top) T T } {(S 1 S 2, T 1 T 2 ) (S 1, T 1 ), (S 2, T 2 ) R} {(S 1 S 2, T 1 T 2 ) (T 1, S 1 ), (S 2, T 2 ) R} {(S, µx.t ) (S, [X µx.t ]T ) R} {(µx.s, T ) ([X µx.s]s, T ) R, T Top, and T µy.t 1 }.
45 Support function The generating function Sm is invertible because the corresponding support function is well-defined: support Sm (S, T ) = if T = Top {(S 1, T 1 ), (S 2, T 2 )} if S = S 1 S 2, T = T 1 T 2 {(T 1, S 1 ), (S 2, T 2 )} if S = S 1 S 2, T = T 1 T 2 {(S, [X µx.t 1 ]T 1 )} if T = µx.t 1 {([X µx.s]s, T )} if S = µx.s T Top, T µx.t 1
46 Correspondence Theorem Let (S, T ) T m T m. Then (S, T ) νs m iff treeof (S, T ) νs.
47 Subtyping iso-recursive types The most common definition of iso-recursive subtyping is the Amber rule, after Cardelli s Amber language (1986): S-Amber Σ, X <: Y S <: T Σ µx.s <: µy.t Quiz. Find recursive types S and T such that S <: T using the equi-recursive definition, but not using the Amber rule. Answer: µx.nat (Nat X) and µx.nat X
48 Conclusion Recursive types can be defined by using µ operator. Recursive types are quite expressive: with it we can embed the whole untyped λ-calculus into well-typed λ-calculus. Iso-recursive is heavy weight with notations, but easy to implement. Equi-recursive is very natural but really needs lots of work to build the type system. Coinduction is a standard method to handle infinite structures. Subtyping relation of equi-recursive types needs to compute the greatest fixed point of a subtyping generating function.
49 Homework (without testing part), , , ,
Chapter 21: Metatheory of Recursive Types. Induction and Coinduction Finite and Infinite Types/Subtyping Membership Checking
Chapter 21: Metatheory of Recursive Types Induction and Coinduction Finite and Infinite Types/Subtyping Membership Checking Review of Chapter 20 Recursive Types Lists NatList =
More informationADT. Typing. Recursive Types. Java. Preliminary: syntax, operational semantics. Untyped lambda calculus. Simply typed lambda calculus
Review Preliminary: syntax, operational semantics Untyped lambda calculus Simply typed lambda calculus Simple extension: tuples, sums, lists Subtyping Typing ADT Universal type: system F Java Recursive
More informationLecture 14: Recursive Types
Lecture 14: Recursive Types Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Programming Languages Pratikakis (CSD) Recursive Types CS546, 2018-2019 1 / 11 Motivation
More informationDerivation for the Necessity of Recursive Types and its Basic Usage
Derivation for the Necessity of Recursive Types and its Basic Usage Philipp Koster Supervised by Prof. Dr. Farhad D. Mehta Seminar AT 2016 1 Abstract This paper derives the need for recursive types by
More informationTypes and Programming Languages. Lecture 5. Extensions of simple types
Types and Programming Languages Lecture 5. Extensions of simple types Xiaojuan Cai cxj@sjtu.edu.cn BASICS Lab, Shanghai Jiao Tong University Fall, 2016 Coming soon Simply typed λ-calculus has enough structure
More informationDesign Principles of Programming Languages. Recursive Types. Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term
Design Principles of Programming Languages Recursive Types Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term Review: what have we learned so far? λ-calculus: function and data can
More informationDesign Principles of Programming Languages. Recursive Types. Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term, 2014
Design Principles of Programming Languages Recursive Types Zhenjiang Hu, Haiyan Zhao, Yingfei Xiong Peking University, Spring Term, 2014 Review: Why learn type theories? Art vs. Knowledge Art cannot be
More informationCS 4110 Programming Languages & Logics. Lecture 28 Recursive Types
CS 4110 Programming Languages & Logics Lecture 28 Recursive Types 7 November 2014 Announcements 2 Foster office hours 11-12pm Guest lecture by Fran on Monday Recursive Types 3 Many languages support recursive
More informationCIS 500 Software Foundations Midterm I Answer key October 8, 2003
CIS 500 Software Foundations Midterm I Answer key October 8, 2003 Inductive Definitions Review: Recall that the function size, which calculates the total number of nodes in the abstract syntax tree of
More informationDerivation for the Necessity of Recursive Types and its Basic Usage
Derivation for the Necessity of Recursive Types and its Basic Usage Philipp Koster Supervised by Prof. Dr. Farhad D. Mehta Seminar AT 2016 1 Abstract With this paper I ll derive the need for recursive
More informationGoal. 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 informationTypes and Programming Languages. Lecture 6. Normalization, references, and exceptions
Types and Programming Languages Lecture 6. Normalization, references, and exceptions Xiaojuan Cai cxj@sjtu.edu.cn BASICS Lab, Shanghai Jiao Tong University Fall, 2016 Coming soon One more language features:
More informationSubsumption. 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 informationThe University of Nottingham
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER 2013-2014 G54FOP FOUNDATIONS OF PROGRAMMING Time allowed 2 hours Candidates may complete the front cover of their
More informationFall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.
Programming Languages Fall 2013 Midterm Exam 10/22/13 Time Limit: 100 Minutes Name (Print): Graduate Center I.D. This is a closed-book, closed-notes exam. Various definitions are provided in the exam.
More informationCS 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,
More informationλ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods
Course 2D1453, 2006-07 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 1903-1995 Church-Turing thesis First
More informationaxiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.
CS 6110 S18 Lecture 18 Denotational Semantics 1 What is Denotational Semantics? So far we have looked at operational semantics involving rules for state transitions, definitional semantics involving translations
More informationProgramming 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 informationCS611 Lecture 33 Equirecursive types & Recursive domain equations November 19, 2001
CS611 Lecture 33 Equirecursive types & Recursive domain equations November 19, 001 Scribe: Hongzhou Liu and Junhwan Kim Lecturer: Andrew Myers 1 Semantics of recursive types, part There are two basic approaches
More informationSymmetry 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 informationCIS 500 Software Foundations Midterm I
CIS 500 Software Foundations Midterm I October 11, 2006 Name: Student ID: Email: Status: Section: registered for the course not registered: sitting in to improve a previous grade not registered: just taking
More informationCS152: 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 informationThe University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER 2012 2013 MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS Time allowed TWO hours Candidates may complete the front
More informationProgramming 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
More informationNegations in Refinement Type Systems
Negations in Refinement Type Systems T. Tsukada (U. Tokyo) 14th March 2016 Shonan, JAPAN This Talk About refinement intersection type systems that refute judgements of other type systems. Background Refinement
More information1 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 informationNatural Numbers. We will use natural numbers to illustrate several ideas that will apply to Haskell data types in general.
Natural Numbers We will use natural numbers to illustrate several ideas that will apply to Haskell data types in general. For the moment we will ignore that fact that each type in Haskell includes possible
More informationLecture Note: Types. 1 Introduction 2. 2 Simple Types 3. 3 Type Soundness 6. 4 Recursive Types Subtyping 17
Jens Palsberg Sep 24, 1999 Contents Lecture Note: Types 1 Introduction 2 2 Simple Types 3 3 Type Soundness 6 4 Recursive Types 12 5 Subtyping 17 6 Decision Procedure for Subtyping 19 7 First-Order Unification
More informationLecture Notes on Data Representation
Lecture Notes on Data Representation 15-814: Types and Programming Languages Frank Pfenning Lecture 9 Tuesday, October 2, 2018 1 Introduction In this lecture we ll see our type system in action. In particular
More informationFormal 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
More informationCMSC 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 informationReview. 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 informationCS 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 informationCS-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 informationThis is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS
1 THE FORMALIZATION OF MATHEMATICS by Harvey M. Friedman Ohio State University Department of Mathematics friedman@math.ohio-state.edu www.math.ohio-state.edu/~friedman/ May 21, 1997 Can mathematics be
More informationConcepts of programming languages
Concepts of programming languages Lecture 5 Wouter Swierstra 1 Announcements Submit your project proposal to me by email on Friday; The presentation schedule in now online Exercise session after the lecture.
More informationChapter 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,
More informationLecture Notes on Program Equivalence
Lecture Notes on Program Equivalence 15-312: Foundations of Programming Languages Frank Pfenning Lecture 24 November 30, 2004 When are two programs equal? Without much reflection one might say that two
More informationRecursive Types. Chapter 7
Chapter 7 Recursive Types By adding special rules for natural numbers to λ, we obtained system T. We may now want to have separate rules for other data structures: lists, binary trees, streams. We can
More informationCSE-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 informationInductive 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 informationOverview. A normal-order language. Strictness. Recursion. Infinite data structures. Direct denotational semantics. Transition semantics
Overview A normal-order language Strictness Recursion Infinite data structures Direct denotational semantics Transition semantics Lazy (call-by-need) evaluation and its semantics A Normal-Order Language
More informationCSE-321 Programming Languages 2011 Final
Name: Hemos ID: CSE-321 Programming Languages 2011 Final Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 15 15 10 17 18 25 100 There are six problems on 18 pages in this exam, including one extracredit
More informationExercise 1 (2+2+2 points)
1 Exercise 1 (2+2+2 points) The following data structure represents binary trees only containing values in the inner nodes: data Tree a = Leaf Node (Tree a) a (Tree a) 1 Consider the tree t of integers
More information9.5 Equivalence Relations
9.5 Equivalence Relations You know from your early study of fractions that each fraction has many equivalent forms. For example, 2, 2 4, 3 6, 2, 3 6, 5 30,... are all different ways to represent the same
More informationλ 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 informationPart 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 informationCIS 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
More informationHomework 3 COSE212, Fall 2018
Homework 3 COSE212, Fall 2018 Hakjoo Oh Due: 10/28, 24:00 Problem 1 (100pts) Let us design and implement a programming language called ML. ML is a small yet Turing-complete functional language that supports
More informationLambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,
Lambda Calculus Type Systems, Lectures 3 Jevgeni Kabanov Tartu, 13.02.2006 PREVIOUSLY ON TYPE SYSTEMS Arithmetical expressions and Booleans Evaluation semantics Normal forms & Values Getting stuck Safety
More informationChapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes
Chapter 13: Reference Why reference Typing Evaluation Store Typings Safety Notes References Mutability So far, what we discussed does not include computational effects (also known as side effects). In
More informationProgramming 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 informationConstrained Types and their Expressiveness
Constrained Types and their Expressiveness JENS PALSBERG Massachusetts Institute of Technology and SCOTT SMITH Johns Hopkins University A constrained type consists of both a standard type and a constraint
More informationPropositional Logic. Part I
Part I Propositional Logic 1 Classical Logic and the Material Conditional 1.1 Introduction 1.1.1 The first purpose of this chapter is to review classical propositional logic, including semantic tableaux.
More informationDenotational 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
More informationThe Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements
CIS 500 Software Foundations Fall 2004 27 September IS 500, 27 September 1 The Lambda Calculus IS 500, 27 September 3 Announcements Homework 1 is graded. Pick it up from Cheryl Hickey (Levine 502). We
More informationRecursive 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 informationCS 4110 Programming Languages & Logics. Lecture 27 Recursive Types
CS 4110 Programming Languages & Logics Lecture 27 Recursive Types 4 November 2016 Announcements 2 My office hours are at the normal time today but canceled on Monday Guest lecture by Seung Hee Han on Monday
More informationLecture 9: Typed Lambda Calculus
Advanced Topics in Programming Languages Spring Semester, 2012 Lecture 9: Typed Lambda Calculus May 8, 2012 Lecturer: Mooly Sagiv Scribe: Guy Golan Gueta and Shachar Itzhaky 1 Defining a Type System for
More informationCIS 500 Software Foundations Fall September 25
CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the
More informationLambda Calculi With Polymorphism
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationMore 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 informationExercise 1 ( = 22 points)
1 Exercise 1 (4 + 3 + 4 + 5 + 6 = 22 points) The following data structure represents polymorphic lists that can contain values of two types in arbitrary order: data DuoList a b = C a (DuoList a b) D b
More informationResources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in...
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationLecture 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
More information- 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
More informationType Systems. Parametric Polymorphism. 1. Recall Let-Polymorphism. 1. Recall Let-Polymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth
Today Parametric Polymorphism Type Systems Lecture 9 Dec. 15th, 2004 Sebastian Maneth 1. Recall Let-Polymorphism 4. System F-sub 5. Properties of F-sub http://lampwww.epfl.ch/teaching/typesystems/2004
More informationCSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p.
CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections 10.1-10.3 p. 1/106 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer
More informationCSC Discrete Math I, Spring Sets
CSC 125 - Discrete Math I, Spring 2017 Sets Sets A set is well-defined, unordered collection of objects The objects in a set are called the elements, or members, of the set A set is said to contain its
More informationFormal 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 informationCOMPUTABILITY THEORY AND RECURSIVELY ENUMERABLE SETS
COMPUTABILITY THEORY AND RECURSIVELY ENUMERABLE SETS JOSHUA LENERS Abstract. An algorithm is function from ω to ω defined by a finite set of instructions to transform a given input x to the desired output
More informationCOMP 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 informationSemantics via Syntax. f (4) = if define f (x) =2 x + 55.
1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from x = 1 [Järvi], with permission of the original author, by copy & let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationFoundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution
Foundations of AI 9. Predicate Logic Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution Wolfram Burgard, Andreas Karwath, Bernhard Nebel, and Martin Riedmiller 09/1 Contents Motivation
More informationInductive datatypes in HOL. lessons learned in Formal-Logic Engineering
Inductive datatypes in HOL lessons learned in Formal-Logic Engineering Stefan Berghofer and Markus Wenzel Institut für Informatik TU München = Isabelle λ β HOL α 1 Introduction Applications of inductive
More informationPart 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 informationProgramming Language Concepts: Lecture 19
Programming Language Concepts: Lecture 19 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 19, 01 April 2009 Adding types
More information3 Pairs and Lists. 3.1 Formal vs. Informal Proofs
3 Pairs and Lists 3.1 Formal vs. Informal Proofs The question of what, exactly, constitutes a proof of a mathematical claim has challenged philosophers throughout the ages. A rough and ready definition,
More information1 Problem Description
Tree Isomorphism: An Exercise in Functional Programming Jayadev Misra 9/10/01 1 Problem Description The problem is to decide if two unordered trees are the same. More precisely, define a binary relation
More informationLambda Calculus as a Programming Language
Cristian Giumale / Lecture Notes 1 Lambda Calculus as a Programming Language The Lambda calculus can be considered as the machine code of a particular computer. Call it the Lambda machine. As in conventional
More informationCostly 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 informationMore 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 informationExercise 1 ( = 18 points)
1 Exercise 1 (4 + 5 + 4 + 5 = 18 points) The following data structure represents polymorphic binary trees that contain values only in special Value nodes that have a single successor: data Tree a = Leaf
More informationPolymorphic 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
More informationLecture #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 information3.4 Deduction and Evaluation: Tools Conditional-Equational Logic
3.4 Deduction and Evaluation: Tools 3.4.1 Conditional-Equational Logic The general definition of a formal specification from above was based on the existence of a precisely defined semantics for the syntax
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationINCREMENTAL SOFTWARE CONSTRUCTION WITH REFINEMENT DIAGRAMS
INCREMENTAL SOFTWARE CONSTRUCTION WITH REFINEMENT DIAGRAMS Ralph-Johan Back Abo Akademi University July 6, 2006 Home page: www.abo.fi/~backrj Research / Current research / Incremental Software Construction
More informationProgramming 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 informationCSE-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 informationFoundations of Computer Science Spring Mathematical Preliminaries
Foundations of Computer Science Spring 2017 Equivalence Relation, Recursive Definition, and Mathematical Induction Mathematical Preliminaries Mohammad Ashiqur Rahman Department of Computer Science College
More informationProgramming Languages Fall 2013
Programming Languages Fall 2013 Lecture 3: Induction Prof. Liang Huang huang@qc.cs.cuny.edu Recursive Data Types (trees) data Ast = ANum Integer APlus Ast Ast ATimes Ast Ast eval (ANum x) = x eval (ATimes
More informationProgram verification. Generalities about software Verification Model Checking. September 20, 2016
Program verification Generalities about software Verification Model Checking Laure Gonnord David Monniaux September 20, 2016 1 / 43 The teaching staff Laure Gonnord, associate professor, LIP laboratory,
More information(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 informationSemantics and Concurrence Module on Semantic of Programming Languages
Semantics and Concurrence Module on Semantic of Programming Languages Pietro Di Gianantonio Università di Udine Presentation Module of 6 credits (48 hours), Semantics of programming languages Describe
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationUniverses. 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 informationCSE-321 Programming Languages 2012 Midterm
Name: Hemos ID: CSE-321 Programming Languages 2012 Midterm Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 14 15 29 20 7 15 100 There are six problems on 24 pages in this exam. The maximum score
More information