Lambda Calculus and Extensions as Foundation of Functional Programming

Size: px
Start display at page:

Download "Lambda Calculus and Extensions as Foundation of Functional Programming"

Transcription

1 Lambda Calculus and Extensions as Foundation of Functional Programming David Sabel and Manfred Schmidt-Schauß 29. September 2015 Lehrerbildungsforum Informatik Last update: 30. September 2015

2 Overview Overview Untyped Lambda Calculus Operational Semantics Contextual Semantics Extension by Data Types D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 2/27

3 Pure (Untyped) Lambda Calculus Lambda Calculus Grammar for expressions e E λ of the pure lambda calculus: e, e i E λ ::= x λx.e (e 1 e 2 ) where x Var λx.e Abstraction (e 1 e 2 ) Application (of e 1 to e 2 ) We may omit brackets for better readability. The body of abstraction extends as far as possible (e 1 e 2 e 3 e 4 ) is reconstructed as (((e 1 e 2 ) e 3 ) e 4 ). Bracketing is left-associative. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 3/27

4 Pure Lambda Calculus: Examples λx.x λx.λy.x λx.λy.λf.f x y (λx.(x x)) (λx.(x x)) The identity function The function that can be applied to two arguments e 1, e 2 and returns e 1. Used as encoding of pairs A lambda-expression which is useless as a program: It is nonterminating. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 4/27

5 Free and Bound Variables free variables FV (e) and bound variables BV (e) are inductively defined: FV (x) :={x}, if x Var BV (x) :=, if x Var FV ((e 1 e 2 )):=FV (e 1 ) FV (e 2 ) BV ((e 1 e 2 )):=BV (e 1 ) BV (e 2 ) FV (λx.e) :=FV (e) \ {x} BV (λx.e) :=BV (e) {x} D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 5/27

6 Renaming Bound Variables α-renaming: λx.e α λx.e[x /x], if x FV (e) and x BV (e) where α-equivalence = α is the smallest congruence obtained from α, i.e. it is inductively defined as e 1 = α α e 2, if e 1 e2 e = α e e 1 = α e 2, if e 2 = α e 1 e 1 = α e 3, if e 1 = α e 2 e 2 = α e 3 C[e 1 ] = α C[e 2 ], if e 1 = α e 2 D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 6/27

7 Variable Convention The Convention on Bound Variables: In the expressions mentioned: binders always bind distinct variables, and bound variables are distinct from free variables. This can always be achieved by α-renamings. Example λx.x(y (λx.λy.y x)): the convention is not satisfied. It can be satisfied by α-renaming: λx.x(y (λx.λy.y x)) = α λx.x(y (λz.λu.u z)) D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 7/27

8 Substitution We define a more general notion of substitution: e 1 [e 2 /x] denotes the substitution of all free occurrences of variable x in e 1 by the expression e 2 : An inductive definition recursing over the expression structure is: x[e/x] := e y[e/x] := y, if x y (λx.e 1 )[e/x] := λx.e 1 (λy.e 1 )[e/x] := λy.(e 1 [e/x]), if x y (e 1 e 2 )[e/x] := (e 1 [e/x] e 2 [e/x]) Due to the distinct variable convention: There is no capture of variables. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 8/27

9 Substitution Examples: Compute (x λx.x)[λy.y / x] (λx.x x) (λy.y y) (x x) [(λy.y y) / x] = (λy.y y) (λy.y y) = α (λx.x x) (λy.y y) D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 9/27

10 Substitution Examples: Compute (x λx.x)[λy.y / x] 1. result of renaming: (x λu.u)[λy.y / x] 2. result of substitution : ((λy.y) λu.u) (λx.x x) (λy.y y) (x x) [(λy.y y) / x] = (λy.y y) (λy.y y) = α (λx.x x) (λy.y y) D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 9/27

11 Some Combinators Example I := λx.x K := λx.λy.x K 2 := λx.λy.y Ω := (λx 1.(x 1 x 1 )) (λx 2.(x 2 x 2 )) Y := λy 1.(λx 1.(y 1 (x 1 x 1 ))) (λy 2.(y 2 (x 2 x 2 ))) The I-combinator is the identity function. K, K2 are projections, and Ω is non-terminating (diverging). The Y -combinator is a fixpoint-combinator, it has the property that Y e c e (Y e) holds. It can be used to express recursion. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 10/27

12 Operational Semantics Small-Step Operational Semantics of the Pure Lazy Lambda-Calculus Beta-Reduction (λx.e 1 ) e 2 β e1 [e 2 /x] C,β We write e 1 e 2, if e 1 = D[e 1 ], e β 1 e 2, and e 2 = D[e 2 ] D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 11/27

13 Operational Semantics: Normal-order reduction Normal order reduction : A deterministic evaluation strategy. Reduce the outermost-leftmost beta-redex: A normal order reduction step no is any β-reduction which is performed inside a reduction context: s no t if s is of the form R[(λx.s 1 ) s 2 ] and t = R[s 1 [s 2 /x]] for a reduction context R. Grammar for reduction contexts: R ::= [ ] (R e) no,+ no, no,i transitive closure of no reflexive-transitive closure exactly i normal order reduction steps. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 12/27

14 Normal-order reduction: WHNF Closed and no -irreducible expressions of the (lazy) lambda calculus are exactly the abstractions. Abstractions are also the weak head normal forms (WHNFs) of the (lazy) lambda calculus. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 13/27

15 Converging Expression Definition An expression e E λ converges (or successfully terminates) (written as e ) iff there exists a sequence of normal order reduction steps starting with e and ending in a WHNF: e iff e no, e where e is a WHNF. If e does not hold, then we say that e diverges and write e. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 14/27

16 Converging Expression Definition An expression e E λ converges (or successfully terminates) (written as e ) iff there exists a sequence of normal order reduction steps starting with e and ending in a WHNF: e iff e no, e where e is a WHNF. If e does not hold, then we say that e diverges and write e. Examples (λx.x) ((λx.λy.x) (λz.z) (λw.w)) : no (λy.λz.z) (λw.w) no λz.z. ((λx.x) (λy.y)) ((λx.x x) (λy.y y)) (x (λy.y) D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 14/27

17 Standardization In order to compute WHNFs from an expression, normal-order reduction is sufficient: Proposition Let e be an expression, such that e C,β, e where e is a WHNF. Then e. s no, C,β, s 0 C,β, s 1 where s 0, s 1 are abstractions ( C,β, is β-reduction at any occurrence) D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 15/27

18 Semantics: Contextual Equivalence Definition contextual equivalence Definition Let e 1, e 2 E λ. Then e 1 and e 2 are contextually equivalent, written as e 1 e 2 iff for all contexts C C λ : C[e 1 ] C[e 2 ]. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 16/27

19 Semantics: Contextual Equivalence Properties of c Contextual preorder is a precongruence (i.e. it is a partial order and s c t = C[s] c C[t] ) Contextual equivalence is a congruence (i.e. it is an equivalence relation and s c t = C[s] c C[t] ) Consequence: if s c t it is possible to replace s by t anywhere in a program P to P and P c P holds. Divergent closed expressions are equivalent: Let e 1, e 2 be two closed expressions with e 1 and e 2. Then e 1 c e 2. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 17/27

20 Connection to Rewriting and Confluence The reduction C,β, is confluen: e 1 C,β, C,β, e s 3 C,β, C,β, e 2 The confluence of C,β, and the standardization of normal-order reduction imply: Theorem β C,β is correct w.r.t. c, i.e. if e 1 e 2 then e 1 c e 2. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 18/27

21 Connection to Rewriting C,β, is called the conversion relation C,β, is a congruence. C,β, c. However : C,β, c. Example: (λx.(x x x) (λx.(x x x)), hence, Ω c (λx.(x x x)) (λx.(x x x)). C,β, But, Ω (λx.(x x x)) (λx.(x x x)), since there is no common reduction successor. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 19/27

22 Extension by Data Types LNAME as a Core Language of Haskell D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 20/27

23 Syntax of LNAME LNAME is an extension of the lazy lambda calculus by three constructs: data: there are primitives for constructing and deconstructing data Sequentialization: seq Supercombinators F: recursive function definitions D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 21/27

24 Summary: Syntax of LNAME For every f F there is a definition of the form f x 1... x n = e where x i are variables and FV (e) {x 1,..., x n }. Syntax Grammar for expressions of LNAME where x, x i Var, f F, and c T,i K T : e, e i E LNAME ::= x λx.e f (e 1 e 2 ) (c T,i e 1... e ar(ct,i )) case T e of {pat T,1 e 1 ;... ; pat T, T e T } seq e 1 e 2 pat T,i ::= (c T,i x i,1... x i,ar(ct,i )) D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 22/27

25 Reductions rules of LNAME β (λx.e 1 ) e 2 e 1 [e 2 /x] (case) (seq) (case T (c T,i e 1... e ar(c T,i ) ) of {... ; (c T,i x i,1... x i,ar(ct,i )) e i ;...}) e i [e 1 /x i,1,..., e ar(c T,i ) /x i,ar(c T,i )] seq v e e, if v is a WHNF. (SCβ) f e 1... e n e[e 1 /x 1,..., e n /x n ], if f x 1... x n = e is the definition of f F. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 23/27

26 Syntax of LNAME Extension by Data There is a finite nonempty set of type constructors T, where for every T T there are pairwise disjoint finite nonempty sets of data constructors D T = {c T,1,... c T, T }. Every constructor has a fixed arity (a non-negative integer) denoted by ar(t ) or ar(c T,j ), The data constructor c T,i of arity n is applied to n expressions to form a constructor application (c T,i e 1... e ar(ct,i )). Case-expressions for analysing and deconstructing data. Examples type constructor Bool (of arity 0) with data constructors True and False type constructor List (of arity 1) with data constructors Nil (of arity 0) and Cons (of arity 2). A list of three elements: (Cons True (Cons False (Cons True Nil))). D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 24/27

27 Recursive Definition of Functions Extension We assume that there is a set F of function symbols, also called supercombinators and that for every f F there is a definition of f of the form f x 1... x n = e where x i are variables and e is an expression s.t. FV (e) {x 1,..., x n }. The names from F are treated as constants, and so may also occur in the defining expressions e on the right hand side. The number n in a definition f x 1... x n = e is called the arity of f and written as ar(f). D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 25/27

28 Recursive Definition of Supercombinators Examples map, head F map F is a recursive supercombinator: map f xs = case List xs of {Nil Nil; (Cons y ys) Cons (f y) (map f ys )} head F is a non-recursive supercombinator: head xs = case List xs of {Nil Ω; (Cons y ys) y} D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 26/27

29 WHNFs of LNAME Definition WHNFs of LNAME are of the form A functional weak head normal form (FWHNF) in LNAME is any abstraction and any expression of the form (f e 1... e m ) where f F and ar(f) > m. A constructor weak head normal form (CWHNF) is any expression of the form (c T,i e 1... e ar(ct,i )). There are no -irreducible closed expressions that are not WHNFs, for example (True True); These are ruled out in typed calculi. D. Sabel & M. Schmidt-Schauß Lambda Calculus and Extensions 27/27

International School on Rewriting (ISR 2015) Rewriting Techniques for Correctness of Program Transformations

International School on Rewriting (ISR 2015) Rewriting Techniques for Correctness of Program Transformations International School on Rewriting (ISR 2015) Rewriting Techniques for Correctness of Program Transformations David Sabel and Manfred Schmidt-Schauß Computer Science Institute Goethe-University Frankfurt

More information

CITS3211 FUNCTIONAL PROGRAMMING

CITS3211 FUNCTIONAL PROGRAMMING CITS3211 FUNCTIONAL PROGRAMMING 9. The λ calculus Summary: This lecture introduces the λ calculus. The λ calculus is the theoretical model underlying the semantics and implementation of functional programming

More information

Lecture 5: The Untyped λ-calculus

Lecture 5: The Untyped λ-calculus Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,

More information

Last class. CS Principles of Programming Languages. Introduction. Outline

Last class. CS Principles of Programming Languages. Introduction. Outline Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting

More information

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonly-used programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java

More information

Lambda Calculus. Lecture 4 CS /26/10

Lambda Calculus. Lecture 4 CS /26/10 Lambda Calculus Lecture 4 CS 565 10/26/10 Pure (Untyped) Lambda Calculus The only value is a function Variables denote functions Functions always take functions as arguments Functions always return functions

More information

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010 Pure (Untyped) λ-calculus Andrey Kruglyak, 2010 1 Pure (untyped) λ-calculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential

More information

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

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

CMSC 330: Organization of Programming Languages

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

Conservative Concurrency in Haskell

Conservative Concurrency in Haskell Conservative Concurrency in Haskell David Sabel and Manfred Schmidt-Schauß Goethe-University, Frankfurt am Main, Germany LICS 12, Dubrovnik, Croatia Motivation a View on Haskell Purely functional core

More information

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08 Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)

More information

1 Scope, Bound and Free Occurrences, Closed Terms

1 Scope, Bound and Free Occurrences, Closed Terms CS 6110 S18 Lecture 2 The λ-calculus Last time we introduced the λ-calculus, a mathematical system for studying the interaction of functional abstraction and functional application. We discussed the syntax

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ August 17, 2007 Lambda Calculus and Type

More information

CMSC 330: Organization of Programming Languages

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

CMSC 330: Organization of Programming Languages. Lambda Calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus CMSC 330: Organization of Programming Languages Lambda Calculus 1 Turing Completeness Turing machines are the most powerful description of computation possible They define the Turing-computable functions

More information

The Untyped Lambda Calculus

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

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

Formal Semantics. Aspects to formalize. Lambda calculus. Approach Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and

More information

Fundamentals and lambda calculus

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

The Untyped Lambda Calculus

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

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 Summer 2017 1 100 years ago Albert Einstein proposed special theory of relativity in 1905 In the paper On the Electrodynamics of

More information

Introduction to the λ-calculus

Introduction to the λ-calculus Announcements Prelim #2 issues: o Problem 5 grading guide out shortly o Problem 3 (hashing) issues Will be on final! Friday RDZ office hours are 11-12 not 1:30-2:30 1 Introduction to the λ-calculus Today

More information

CMSC 330: Organization of Programming Languages. Lambda Calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus CMSC 330: Organization of Programming Languages Lambda Calculus 1 100 years ago Albert Einstein proposed special theory of relativity in 1905 In the paper On the Electrodynamics of Moving Bodies 2 Prioritätsstreit,

More information

Pure Lambda Calculus. Lecture 17

Pure Lambda Calculus. Lecture 17 Pure Lambda Calculus Lecture 17 Lambda Calculus Lambda Calculus (λ-calculus) is a functional notation introduced by Alonzo Church in the early 1930s to formalize the notion of computability. Pure λ-calculus

More information

An Abstract Machine for Concurrent Haskell with Futures

An Abstract Machine for Concurrent Haskell with Futures An Abstract Machine for Concurrent Haskell with Futures David Sabel Goethe-University, Frankfurt am Main, Germany ATPS 12, Berlin, Germany Motivation Concurrent Haskell (Peyton Jones, Gordon, Finne 1996)

More information

Introduction to Lambda Calculus. Lecture 7 CS /08/09

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

Observational Program Calculi and the Correctness of Translations

Observational Program Calculi and the Correctness of Translations Observational Program Calculi and the Correctness of Translations Manfred Schmidt-Schauß a, David Sabel a, Joachim Niehren b, Jan Schwinghammer a Goethe-University Frankfurt am Main, Germany b INRIA Lille,

More information

Safety of Nöcker s strictness analysis

Safety of Nöcker s strictness analysis JFP 18 (4): 503 551, 2008. c 2007 Cambridge University Press doi:10.1017/s0956796807006624 First published online 8 November 2007 Printed in the United Kingdom 503 Safety of Nöcker s strictness analysis

More information

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

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

Activity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?

Activity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable? Activity CSCI 334: Principles of Programming Languages Lecture 4: Fundamentals II Write a function firsts that, when given a list of cons cells, returns a list of the left element of each cons. ( (a. b)

More information

Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)

Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides) Fundamentals and lambda calculus Deian Stefan (adopted from my & Edward Yang s CSE242 slides) Logistics Assignments: Programming assignment 1 is out Homework 1 will be released tomorrow night Podcasting:

More information

Chapter 5: The Untyped Lambda Calculus

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

CMSC 330: Organization of Programming Languages

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

Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators

Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer Polytechnic Institute February 11, 2010 C. Varela 1

More information

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

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

Introduction to the Lambda Calculus

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

dynamically typed dynamically scoped

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

A Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus

A Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus A Quick Overview CAS 701 Class Presentation 18 November 2008 Lambda Department of Computing & Software McMaster University 1.1 Outline 1 2 3 Lambda 4 5 6 7 Type Problem Lambda 1.2 Lambda calculus is a

More information

VU Semantik von Programmiersprachen

VU Semantik von Programmiersprachen VU Semantik von Programmiersprachen Agata Ciabattoni Institute für Computersprachen, Theory and Logic group (agata@logic.at) (A gentle) Introduction to λ calculus p. 1 Why shoud I studyλcalculus? p. 2

More information

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

Correctness of Copy in Calculi with Letrec, Case and Constructors

Correctness of Copy in Calculi with Letrec, Case and Constructors Correctness of Copy in Calculi with Letrec, Case and Constructors Manfred Schmidt-Schauß FB Informatik und Mathematik, Institut für Informatik, J.W.Goethe-Universität, obert-mayer-str 11-15, Postfach 11

More information

Type Systems Winter Semester 2006

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

Lambda Calculus. Variables and Functions. cs3723 1

Lambda Calculus. Variables and Functions. cs3723 1 Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can

More information

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

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

CMSC330. Objects, Functional Programming, and lambda calculus

CMSC330. Objects, Functional Programming, and lambda calculus CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Object-oriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed

More information

Lambda Calculus. Lambda Calculus

Lambda Calculus. Lambda Calculus Lambda Calculus Formalism to describe semantics of operations in functional PLs Variables are free or bound Function definition vs function abstraction Substitution rules for evaluating functions Normal

More information

Concepts of programming languages

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

CSE 505: Concepts of Programming Languages

CSE 505: Concepts of Programming Languages CSE 505: Concepts of Programming Languages Dan Grossman Fall 2003 Lecture 6 Lambda Calculus Dan Grossman CSE505 Fall 2003, Lecture 6 1 Where we are Done: Modeling mutation and local control-flow Proving

More information

3.1 λ-calculus: Syntax

3.1 λ-calculus: Syntax 3 The Lambda Calculus The Lambda calculus, or λ-calculus, is a model of computation based on the idea that algorithms can be seen as mathematical functions mapping inputs to outputs. It was introduced

More information

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus 1 Computer Science 203 Programming Languages Fall 2004 Lecture 10 Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus Plan Informal discussion of procedures and bindings Introduction

More information

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

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

Formal Systems and their Applications

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

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013 Constraint-based Analysis Harry Xu CS 253/INF 212 Spring 2013 Acknowledgements Many slides in this file were taken from Prof. Crista Lope s slides on functional programming as well as slides provided by

More information

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

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

CS 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

Functional programming languages

Functional programming languages Functional programming languages Part I: interpreters and operational semantics Xavier Leroy INRIA Paris-Rocquencourt MPRI 2-4, 2016 2017 X. Leroy (INRIA) Functional programming languages MPRI 2-4, 2016

More information

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008 CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008 Contents 1 Solution to the Exercise 1 1.1 Semantics for lambda calculus.......................

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Concepts in Programming Languages Recitation 5: Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and

More information

CMSC 330: Organization of Programming Languages. Lambda Calculus Encodings

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

Conservative Concurrency in Haskell

Conservative Concurrency in Haskell Conservative Concurrency in Haskell David Sabel and Manfred Schmidt-Schauß Computer Science Institute, Goethe-University, Frankfurt am Main, Germany Email: {sabel,schauss}@ki.informatik.uni-frankfurt.de

More information

CITS3211 FUNCTIONAL PROGRAMMING. 14. Graph reduction

CITS3211 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

The Untyped Lambda Calculus

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

Lambda Calculus-2. Church Rosser Property

Lambda Calculus-2. Church Rosser Property Lambda Calculus-2 Church-Rosser theorem Supports referential transparency of function application Says if it exists, normal form of a term is UNIQUE 1 Church Rosser Property Fundamental result of λ-calculus:

More information

lambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion.

lambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion. lambda calculus Jianguo Lu 1 History Lambda calculus A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion. Introduced by Alonzo Church in 1930s. The calculus can

More information

Functional Programming. Overview. Topics. Recall λ-terms. Examples

Functional Programming. Overview. Topics. Recall λ-terms. Examples Topics Functional Programming Christian Sternagel Harald Zankl Evgeny Zuenko Department of Computer Science University of Innsbruck WS 2017/2018 abstract data types, algebraic data types, binary search

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Advanced Topics in Programming Languages Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming

More information

CMSC 330: Organization of Programming Languages

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

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

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

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright Instructors. History Formal mathematical system Simplest programming language Intended for studying functions, recursion

More information

The University of Nottingham

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

Chapter 5: The Untyped Lambda Calculus

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

Lambda Calculus. Concepts in Programming Languages Recitation 6:

Lambda Calculus. Concepts in Programming Languages Recitation 6: Concepts in Programming Languages Recitation 6: Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming

More information

λ calculus is inconsistent

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

More information

Realising nondeterministic I/O in the Glasgow Haskell Compiler

Realising nondeterministic I/O in the Glasgow Haskell Compiler Realising nondeterministic I/O in the Glasgow Haskell Compiler Technical Report Frank-17 David Sabel Institut für Informatik Johann Wolfgang Goethe-Universität Frankfurt, Germany Email: sabel@informatik.uni-frankfurt.de

More information

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

5. Introduction to the Lambda Calculus. Oscar Nierstrasz 5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming

More information

Lexicografie computationala Feb., 2012

Lexicografie computationala Feb., 2012 Lexicografie computationala Feb., 2012 Anca Dinu University of Bucharest Introduction When we construct meaning representations systematically, we integrate information from two different sources: 1. The

More information

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

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

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

More information

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

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

Recursive Definitions, Fixed Points and the Combinator

Recursive Definitions, Fixed Points and the Combinator Recursive Definitions, Fixed Points and the Combinator Dr. Greg Lavender Department of Computer Sciences University of Texas at Austin Recursive Self-Reference Recursive self-reference occurs regularly

More information

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

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

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

Programming Languages Lecture 15: Recursive Types & Subtyping

Programming Languages Lecture 15: Recursive Types & Subtyping CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)

More information

Programming Languages

Programming Languages Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,

More information

> module Lambda where > import Data.List -- I need some standard list functions

> module Lambda where > import Data.List -- I need some standard list functions Lecture 9 Lambda Calculus We now look at lambda calculus, the theoretical stuff that underlies functional programming. It was introduced by Alonzo Church to formalise two key concepts when dealing with

More information

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21 Functions as data Massimo Merro 9 November 2011 Massimo Merro The Lambda language 1 / 21 The core of sequential programming languages In the mid 1960s, Peter Landin observed that a complex programming

More information

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λ-calculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,

More information

2.1 The λ-calculus Syntax

2.1 The λ-calculus Syntax 2- The λ-calculus 2. The λ-calculus In the previous section, we introduced the concepts of logic and proofs. We shall now present the notion of programs and computations through the so-called λ-calculus.

More information

Graphical Untyped Lambda Calculus Interactive Interpreter

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

Course Notes Equational Programming: Lambda Calculus. Femke van Raamsdonk

Course Notes Equational Programming: Lambda Calculus. Femke van Raamsdonk Course Notes Equational Programming: Lambda Calculus Femke van Raamsdonk November 8, 2018 2 Contents 1 Introduction 5 2 Terms and Reduction 7 2.1 Lambda terms............................ 7 2.2 Beta reduction............................

More information

CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008.

CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008. CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008 Contents 1 Announcements 1 2 Solution to the Eercise 1 3 Introduction 1 4 Multiple

More information

Accurate Step Counting

Accurate Step Counting Accurate Step Counting Catherine Hope and Graham Hutton University of Nottingham Abstract Starting with an evaluator for a language, an abstract machine for the same language can be mechanically derived

More information

Lecture Note: Types. 1 Introduction 2. 2 Simple Types 3. 3 Type Soundness 6. 4 Recursive Types Subtyping 17

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

Functional Programming

Functional Programming Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming

More information

CIS 500 Software Foundations Fall September 25

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

Chapter 2 The Language PCF

Chapter 2 The Language PCF Chapter 2 The Language PCF We will illustrate the various styles of semantics of programming languages with an example: the language PCF Programming language for computable functions, also called Mini-ML.

More information

Inductive Definitions, continued

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

More information

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson Lambda Calculus CS 550 Programming Languages Jeremy Johnson 1 Lambda Calculus The semantics of a pure functional programming language can be mathematically described by a substitution process that mimics

More information

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242 Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

More information

Introduction to lambda calculus Part 3

Introduction to lambda calculus Part 3 Introduction to lambda calculus Part 3 Antti-Juhani Kaijanaho 2017-01-27... 1 Untyped lambda calculus... 2 Typed lambda calculi In an untyped lambda calculus extended with integers, it is required that

More information

CSE-321 Programming Languages 2011 Final

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