Polymorphism and System-F (OV)
|
|
- Jesse Parsons
- 6 years ago
- Views:
Transcription
1 Polymorphism and System-F (OV) Theorie der Programmierung SoSe 2014 FAU
2 the occurrence of something in several different forms Polymorphism?
3 Polymorphic systems Type systems that allow a single piece of code to be used with multiple types [... ] (Pierce, Types and Programming Languages (2002))
4 Polymorphic systems Examples Operator overloading in C++ int operator+(int, int); string operator+(const string&, const string&);... int n = 5 + 3; string s = "hello" + " " + "world";
5 Polymorphic systems Examples Method overriding C++ class C {... public: int dosomething(); } class D: public C {... public: int dosomething(); } int a = C().doSomething() + D().doSomething();
6 Polymorphic systems Examples Dynamic dispatch in Java interface Figure { public void draw(); } class Circle implements Figure {... } class Triangle implements Figure {... }... public void drawall(figure [] figs) { for (int i = 0; i < figs.length; i++) { figs[i].draw(); } }
7 Polymorphic systems Examples Generics in Java class Stack<T> { public Stack() {... } public T top() {... } public void pop() {... } public void push(t e) {... } }... public void dosomething() { Stack<Integer> si =... Stack<String> ss =... si.push(42); ss.push("hello"); }
8 Polymorphic systems Examples Polymorphic datatypes and functions in Haskell data List a = Nil Cons a (List a) append :: List a -> List a -> List a append Nil ys = ys append (Cons x xs) ys = Cons x (append xs ys)
9 A classification of polymorphism Parametric polymorphism. Ad-hoc polymorphism. A single portion of code is given a generic type. The behaviour is uniform on all instances. Each instance may exhibit a different behaviour. - Terminology is from Strachey, Fundamental Concepts in Programming Languages (1967) - We follow Pierce, Types and Programming Languages (2002)
10 Polymorphic systems Revisited Operator overloading in C++ int operator+(int, int); string operator+(const string&, const string&);... int n = 5 + 3; string s = "hello" + " " + "world";
11 Polymorphic systems Revisited Operator overloading in C++ Ad-hoc! int operator+(int, int); string operator+(const string&, const string&);... int n = 5 + 3; string s = "hello" + " " + "world";
12 Polymorphic systems Revisited Method overriding C++ class C {... public: int dosomething(); } class D: public C {... public: int dosomething(); } int a = C().doSomething() + D().doSomething();
13 Polymorphic systems Revisited Method overriding C++ Ad-hoc! class C {... public: int dosomething(); } class D: public C {... public: int dosomething(); } int a = C().doSomething() + D().doSomething();
14 Polymorphic systems Revisited Dynamic dispatch in Java interface Figure { public void draw(); } class Circle implements Figure {... } class Triangle implements Figure {... }... public void drawall(figure [] figs) { for (int i = 0; i < figs.length; i++) { figs[i].draw(); } }
15 Polymorphic systems Revisited Dynamic dispatch in Java Ad-hoc! interface Figure { public void draw(); } class Circle implements Figure {... } class Triangle implements Figure {... }... public void drawall(figure [] figs) { for (int i = 0; i < figs.length; i++) { figs[i].draw(); } }
16 Polymorphic systems Revisited Polymorphic datatypes and functions in Haskell data List a = Nil Cons a (List a) append :: List a -> List a -> List a append Nil ys = ys append (Cons x xs) ys = Cons x (append xs ys)
17 Polymorphic systems Revisited Polymorphic datatypes and functions in Haskell Parametric! data List a = Nil Cons a (List a) append :: List a -> List a -> List a append Nil ys = ys append (Cons x xs) ys = Cons x (append xs ys)
18 Polymorphic systems Revisited Generics in Java class Stack<T> { public Stack() {... } public T top() {... } public void pop() {... } public void push(t e) {... }... public void dosomething() { Stack<Integer> si =... Stack<String> ss =... si.push(42); ss.push("hello"); } }
19 Polymorphic systems Revisited Generics in Java Parametric...? class Stack<T> { public Stack() {... } public T top() {... } public void pop() {... } public void push(t e) {... }... public void dosomething() { Stack<Integer> si =... Stack<String> ss =... si.push(42); ss.push("hello"); } }
20 Polymorphic systems Revisited Generics in Java... are not necessarily uniform!! class Stack<T> { public Stack() {... } public T top() {... } public void pop() {... } public void push(t e) { if ( e instanceof String ) { dosomethingweird((string) e); } else { donormalpush(e); } } }
21 Parametric polymorphism (true) polymorphism Ad-hoc polymorphism in all its flavours is a nice convenience (but in the end just a bunch of functions that share the same name) Parametric polymorphism is more fundamental and powerful (in a way to be made precise later) Up next: a polymorphic type system for the λ-calculus
22 Parametric polymorphism (true) polymorphism Ad-hoc polymorphism in all its flavours is a nice convenience (but in the end just a bunch of functions that share the same name) Parametric polymorphism is more fundamental and powerful (in a way to be made precise later) Up next: a polymorphic type system for the λ-calculus! Why is the STLC not enough?
23 Recap: the STLC Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β
24 Recap: the STLC Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β Polymorphism in practice, a silly example id :: a -> a id = \x -> x (Haskell code) silly :: Int silly = (\x y -> x) (id True) (id 42) Can we type silly in the STLC?
25 System F Discovered almost simultaneously by: Girard (1972), while working on proof-theory Reynolds (1974), while working on polymorphism (he called it polymorphic λ-calculus )
26 System F Discovered almost simultaneously by: Girard (1972), while working on proof-theory Reynolds (1974), while working on polymorphism (he called it polymorphic λ-calculus )! Two versions of System-F: à la Curry and à la Church! We shall see both
27 From STLC to System F (à la Curry) Types: α, β ::= a α β (a TypeVars) Terms: s, t ::= x st λx.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β
28 From STLC to System F (à la Curry) Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β
29 From STLC to System F (à la Curry) Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α
30 From STLC to System F (à la Curry) Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α ( e) Γ s : a.α Γ s : (α[a := β])
31 From STLC to System F (à la Curry) Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α ( e) Γ s : a.α Γ s : (α[a := β]) We can indeed type silly in System F!
32 Some basic properties of System F Theorem (Preservation straightforward proof) If Γ s : α and s β t, then Γ t : α. Theorem (Normalization Girard (1972)) If Γ s : α, then s is strongly normalizing.
33 Some basic properties of System F In fact: any computable function proved total using SO Arithmetic can be written in System F! All primitive recursive functions Even the Ackermann function Intuition: a compiler an interpreter
34 Church encoding in System F Natural numbers N := a.(a a) a a zero : N zero = λf a. a succ : N N succ = λn f a. f (n f a)
35 Church encoding in System F Natural numbers N := a.(a a) a a zero : N zero = λf a. a succ : N N succ = λn f a. f (n f a) add : N N N add = λn m. n succ m
36 Church encoding in System F Natural numbers N := a.(a a) a a zero : N zero = λf a. a succ : N N succ = λn f a. f (n f a) add : N N N add = λn m. n succ m mul : N N N mul = λn m. n (add m) zero
37 Church encodings in System F Natural numbers derivation of succ : N N N := a.(a a) a a Γ := n : N, f : a a, x : a Γ f : a a Γ n f x : a ( e) Γ f (n f x) : a ( i ) 2 n : N λf x. f (n f x) : (a a) a a ( i ) ( i ). n : N λf x. f (n f x) : N λn f x. f (n f x) : N N
38 Church encodings in System F Natural numbers derivation of succ : N N N := a.(a a) a a Γ := n : N, f : a a, x : a ( e) ( e) Γ n : a.(a a) a a Γ n : (a a) a a Γ f : a a Γ n f : a a ( e) Γ n f x : a. Γ f : a a Γ n f x : a ( e) Γ f (n f x) : a ( i ) 2 n : N λf x. f (n f x) : (a a) a a ( i ) ( i ) n : N λf x. f (n f x) : N λn f x. f (n f x) : N N Γ x : a
39 Church encoding in System F Products (a b) := r.(a b r) r pair : a b. a b (a b) pair =... fst : a b. (a b) a fst =... snd : a b. (a b) b snd =...
40 Church encoding in System F Products (a b) := r.(a b r) r pair : a b. a b (a b) pair = λ x y f. f x y fst : a b. (a b) a fst = λ p. p (λx y. x) snd : a b. (a b) b snd = λ p. p (λx y. y)
41 Church encoding in System F Products (a b) := r.(a b r) r pair : a b. a b (a b) pair = λ x y f. f x y fst : a b. (a b) a fst = λ p. p (λx y. x) snd : a b. (a b) b snd = λ p. p (λx y. y) How many non-equivalent implementations admits (a b) a?
42 Church encoding in System F Sums/co-products (a + b) := r.(a r) (b r) r injl : a b. a (a + b) injl =... injr : a b. b (a + b) injr =... case : a b s.(a s) (b s) (a + b) s case =...
43 Church encoding in System F Sums/co-products (a + b) := r.(a r) (b r) r injl : a b. a (a + b) injl = λ x f g. f x injr : a b. b (a + b) injr = λ y f g. g y case : a b s.(a s) (b s) (a + b) s case =...
44 Church encoding in System F Sums/co-products (a + b) := r.(a r) (b r) r injl : a b. a (a + b) injl = λ x f g. f x injr : a b. b (a + b) injr = λ y f g. g y case : a b s.(a s) (b s) (a + b) s case = λ f g p. p f g
45 Church encoding in System F Sums/co-products (a + b) := r.(a r) (b r) r injl : a b. a (a + b) injl = λ x f g. f x injr : a b. b (a + b) injr = λ y f g. g y case : a b s.(a s) (b s) (a + b) s case = λ f g p. p f g Can these types be implemented in an essentially different way?
46 Church encoding in System F Lists List a := r.r (a r r) r nil : a. List a nil =... cons : a. a List a List a cons =... length : a. List a N length =...
47 Church encoding in System F Lists List a := r.r (a r r) r nil : a. List a nil = λ u f. u cons : a. a List a List a cons = λ x l u f. f x (l u f ) length : a. List a N length =...
48 Church encoding in System F Lists List a := r.r (a r r) r nil : a. List a nil = λ u f. u cons : a. a List a List a cons = λ x l u f. f x (l u f ) length : a. List a N length = λ l. l zero (λx r. succ r)
49 Parametricity or why uniformity matters Intuition If we write a function with type a.α(a) we can t do anything on a-values fewer things can go wrong! - Introduced by Reynolds,Types, abstraction and parametric polymorphism (1983) as abstraction - Wadler s Theorems for free! (1989) uses it to derive free-theorems from polymorphic types
50 Parametricity or why uniformity matters Example singleton :: a -> List a singleton =... singletonint :: Int -> List Int singletonint =... If we want to be 100% sure of their correctness... how many unit tests do we need in each case? - Introduced by Reynolds,Types, abstraction and parametric polymorphism (1983) as abstraction - Wadler s Theorems for free! (1989) uses it to derive free-theorems from polymorphic types
51 All is very nice and good but...
52 All is very nice and good but... Theorem Type checking in System F à la Curry is undecidable. - Wells, Typability and type checking in the second-order lambda-calculus are equivalent and undecidable. (1994)
53 Where do we go from here? Use a weaker system Hindley-Milner type system Rank-2 polymorphism Add type annotations to λ-terms System F à la Church
54 Hindler-Milner types a weaker but practical system Roughly speaking... Types are restricted to prenex form : a b c.((a b) c) a.(( b.(a b)) a) Type instantiation restricted to quantifier-free types. ( -elimination needs to be modified)
55 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α ( e) Γ s : a.α Γ s : (α[a := β]) Reduction rules: (λx.s)t β s[x := t]
56 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx:α.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α ( e) Γ s : a.α Γ s : (α[a := β]) Reduction rules: (λx.s)t β s[x := t]
57 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx:α.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx:α.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α ( e) Γ s : a.α Γ s : (α[a := β]) Reduction rules: (λx.s)t β s[x := t]
58 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx:α.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx:α.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ s : a.α ( e) Γ s : a.α Γ s : (α[a := β]) Reduction rules: (λ x:α.s)t β s[x := t]
59 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx:α.s Λa.s (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx:α.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ Λa.s : a.α ( e) Γ s : a.α Γ s : (α[a := β]) Reduction rules: (λ x:α.s)t β s[x := t]
60 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx:α.s Λa.s s@α (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx:α.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ Λa.s : a.α ( e) Γ s : a.α Γ s@β : (α[a := β]) Reduction rules: (λ x:α.s)t β s[x := t]
61 System F, from Curry to Church Types: α, β ::= a α β a.α (a TypeVars) Terms: s, t ::= x st λx:α.s Λa.s s@α (x TermVars) Typing rules: (axiom) Γ, x : α x : α ( i ) Γ, x : α s : β Γ λx:α.s : α β ( e) Γ s : α β Γ t : α Γ st : β ( i ) Γ s : α a / FV (Γ ) Γ Λa.s : a.α ( e) Γ s : a.α Γ s@β : (α[a := β]) Reduction rules: (λ x:α.s)t β s[x := t] (Λa.s)@α β s[a := α]
62 System F á la Church Examples id : a.a a id = Λa. λx:a. x f : Nat Nat f = λx:nat. succ (id@nat x)
Polymorphic 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 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 informationFaith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh
Faith, Evolution, and Programming Languages Philip Wadler University of Edinburgh Evolution Multiculturalism Part I Church: The origins of faith Gerhard Gentzen (1909 1945) Gerhard Gentzen (1935) Natural
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 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 informationType Systems Winter Semester 2006
Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006 - version 1.1 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial
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 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 informationHarvard 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 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 informationType-indexed functions in Generic Haskell
Type-indexed functions in Generic Haskell Johan Jeuring September 15, 2004 Introduction Today I will talk about: a Types of polymorphism. b Type-indexed functions. c Dependencies. Read about b, and c in
More informationProgramming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.
CMSC 330: Organization of Programming Languages Lambda Calculus Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying or tuples
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying
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 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 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 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 informationTypes and Type Inference
Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion
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 informationCITS3211 FUNCTIONAL PROGRAMMING. 10. Programming in the pure λ calculus
CITS3211 FUNCTIONAL PROGRAMMING 10. Programming in the pure λ calculus Summary: This lecture demonstates the power of the pure λ calculus by showing that there are λ expressions that can be used to emulate
More informationThe Lambda Calculus. notes by Don Blaheta. October 12, A little bondage is always a good thing. sk
The Lambda Calculus notes by Don Blaheta October 2, 2000 A little bondage is always a good thing. sk We ve seen that Scheme is, as languages go, pretty small. There are just a few keywords, and most of
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 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 informationM. Snyder, George Mason University LAMBDA CALCULUS. (untyped)
1 LAMBDA CALCULUS (untyped) 2 The Untyped Lambda Calculus (λ) Designed by Alonzo Church (1930s) Turing Complete (Turing was his doctoral student!) Models functions, always as 1-input Definition: terms,
More informationIntroduction to the Lambda Calculus
Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et
More informationProgramming with Math and Logic
.. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing
More informationFunctional Languages and Higher-Order Functions
Functional Languages and Higher-Order Functions Leonidas Fegaras CSE 5317/4305 L12: Higher-Order Functions 1 First-Class Functions Values of some type are first-class if They can be assigned to local variables
More informationExercise 1 ( = 24 points)
1 Exercise 1 (4 + 5 + 4 + 6 + 5 = 24 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 =
More informationCMSC 330: Organization of Programming Languages. Lambda Calculus Encodings
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC330 Spring 2018 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!
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 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 informationHarvard 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 informationLambda 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 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 informationTradeoffs. 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 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 informationOne of a number of approaches to a mathematical challenge at the time (1930): Constructibility
λ Calculus Church s λ Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Summer 2017 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!
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 informationVerifying Program Invariants with Refinement Types
Verifying Program Invariants with Refinement Types Rowan Davies and Frank Pfenning Carnegie Mellon University Princeton and Yale Colloquium Talks February, 2001 Acknowledgments: Robert Harper 1 Overview
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 informationLesson 11 Universal Types. Universal Types and System F
Lesson 11 Universal Types 2/28 Chapter 23 Universal Types and System F Varieties of polymorphism System F Examples Basic properties Erasure Evaluation issues Parametricity Impredicativity Lesson 11: Universal
More informationBasic 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 informationCSE 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 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 informationCSE-321 Programming Languages 2014 Final
Name: Hemos ID: CSE-321 Programming Languages 2014 Final Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 Total Score Max 15 12 14 14 30 15 100 There are six problems on 12 pages in this exam.
More informationLambda calculus. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 6
Lambda calculus Advanced functional programming - Lecture 6 Wouter Swierstra and Alejandro Serrano 1 Today Lambda calculus the foundation of functional programming What makes lambda calculus such a universal
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 informationSecond-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 informationTypes and Type Inference
CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of
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 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 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 informationAdvances in Programming Languages
Advances in Programming Languages Lecture 4: Higher Polymorphism Ian Stark School of Informatics The University of Edinburgh Friday 30 September 2016 Semester 1 Week 2 https://blog.inf.ed.ac.uk/apl16 Topic:
More informationStructural polymorphism in Generic Haskell
Structural polymorphism in Generic Haskell Andres Löh andres@cs.uu.nl 5 February 2005 Overview About Haskell Genericity and other types of polymorphism Examples of generic functions Generic Haskell Overview
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 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 informationLambda 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/ October 13, 2004 Lambda Calculus and Type
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Spring 2017 1 Review A lambda calculus expression is defined as e ::= x variable λx.e abstraction (fun def) e e application
More informationCS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:
More informationFundamentals and lambda calculus
Fundamentals and lambda calculus Again: JavaScript functions JavaScript functions are first-class Syntax is a bit ugly/terse when you want to use functions as values; recall block scoping: (function ()
More informationType Systems. Pierce Ch. 3, 8, 11, 15 CSE
Type Systems Pierce Ch. 3, 8, 11, 15 CSE 6341 1 A Simple Language ::= true false if then else 0 succ pred iszero Simple untyped expressions Natural numbers encoded as succ succ
More informationType Checking and Type Inference
Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled
More informationIntroduction to Lambda Calculus. Lecture 7 CS /08/09
Introduction to Lambda Calculus Lecture 7 CS 565 02/08/09 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)
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 informationCSE-321 Programming Languages 2010 Midterm
Name: Hemos ID: CSE-321 Programming Languages 2010 Midterm Score Prob 1 Prob 2 Prob 3 Prob 4 Total Max 15 30 35 20 100 1 1 SML Programming [15 pts] Question 1. [5 pts] Give a tail recursive implementation
More informationGirard s System F. Chapter System F. = λ ( f :τ 2 τ 3 ) λ (g:τ 1 τ 2 ) λ (x:τ 1 ) f (g(x)) System F
174 20.1 System F 20.1 System F Chapter 20 Girard s System F The languages we have considered so far are all monomorphic in that every expression has a unique type, given the types of its free variables,
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 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 informationLambda calculus. Chapter 2
Chapter 2 Lambda calculus The lambda calculus serves as the basis of most functional programming languages. More accurately, we might say that functional programming languages are based on the lambda calculi
More informationLecture 4: Higher Order Functions
Lecture 4: Higher Order Functions Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 26, 2017 HIGHER ORDER FUNCTIONS The order of a function
More informationWhereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions
Whereweare CS-XXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave
More informationCalculus 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 informationCS558 Programming Languages
CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And
More informationLet Arguments Go First
Let Arguments Go First Ningning Xie and Bruno C. d. S. Oliveira The University of Hong Kong {nnxie,bruno}@cs.hku.hk Abstract. Bi-directional type checking has proved to be an extremely useful and versatile
More informationRecursive 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 informationFaith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh
Faith, Evolution, and Programming Languages Philip Wadler University of Edinburgh Evolution Multiculturalism Static vs. Dynamic Typing Part I. Church: The origins of faith Part II. Haskell: Type Classes
More informationFrom Math to Machine A formal derivation of an executable Krivine Machine Wouter Swierstra Brouwer Seminar
From Math to Machine A formal derivation of an executable Krivine Machine Wouter Swierstra Brouwer Seminar β reduction (λx. t0) t1 t0 {t1/x} Substitution Realizing β-reduction through substitution is a
More informationCOMP 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 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 informationParametricity and Dependent Types
Parametricity and Dependent Types Jean-Philippe Bernardy Patrik Jansson Chalmers University of Technology and University of Gothenburg {bernardy,patrikj}@chalmers.se Ross Paterson City University London
More informationCS-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 informationdynamically typed dynamically scoped
Reference Dynamically Typed Programming Languages Part 1: The Untyped λ-calculus Jim Royer CIS 352 April 19, 2018 Practical Foundations for Programming Languages, 2/e, Part VI: Dynamic Types, by Robert
More informationLecture slides & distribution files:
Type Theory Lecture slides & distribution files: http://www.cs.rhul.ac.uk/home/zhaohui/ttlectures.html Zhaohui Luo Department of Computer Science Royal Holloway, University of London April 2011 2 Type
More informationGraphical Untyped Lambda Calculus Interactive Interpreter
Graphical Untyped Lambda Calculus Interactive Interpreter (GULCII) Claude Heiland-Allen https://mathr.co.uk mailto:claude@mathr.co.uk Edinburgh, 2017 Outline Lambda calculus encodings How to perform lambda
More informationPolymorphism and Type Inference
Polymorphism and Type Inference Volker Stolz stolz@ifi.uio.no INF 3110-2008 Department of Informatics University of Oslo Initially by Gerardo Schneider. Based on John C. Mitchell s slides (Stanford U.)
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Tuesday, February 19, 2013 The lambda calculus (or λ-calculus) was introduced by Alonzo Church and Stephen Cole Kleene in
More informationProgramming in Omega Part 1. Tim Sheard Portland State University
Programming in Omega Part 1 Tim Sheard Portland State University Tim Sheard Computer Science Department Portland State University Portland, Oregon PSU PL Research at Portland State University The Programming
More informationCIS 500 Software Foundations Fall December 4
CIS 500 Software Foundations Fall 2006 December 4 Administrivia Homework 11 Homework 11 is currently due on Friday. Should we make it due next Monday instead? More on Evaluation Contexts Progress for FJ
More informationTheorem Proving Principles, Techniques, Applications Recursion
NICTA Advanced Course Theorem Proving Principles, Techniques, Applications Recursion 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic,
More informationWriting 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 informationType assignment for intersections and unions in call-by-value languages
Type assignment for intersections and unions in call-by-value languages Joshua Dunfield and Frank Pfenning Triple Project Carnegie Mellon University 8 April 2003 FOSSACS 03, Warsaw, Poland Type assignment
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 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 informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Use currying
More informationGeneric polymorphism on steroids
Generic polymorphism on steroids or How to Solve the Expression Problem with Polymorphic Variants Claudio Sacerdoti Coen Dipartimento di Informatica Scienza e Ingegneria
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative
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 informationCITS3211 FUNCTIONAL PROGRAMMING. 14. Graph reduction
CITS3211 FUNCTIONAL PROGRAMMING 14. Graph reduction Summary: This lecture discusses graph reduction, which is the basis of the most common compilation technique for lazy functional languages. CITS3211
More information