A Representation of Terms of the Lambda-Calculus in Standard ML

Size: px
Start display at page:

Download "A Representation of Terms of the Lambda-Calculus in Standard ML"

Transcription

1 A Representation of Terms of the Lambda-Calculus in Standard ML Matthew Wahab April 30, 2006 Abstract Representing terms of the λ-calculus is complicated by the need to uniquely associate bound variables with their binding terms. Using Standard ML, a representation of λ-terms based on the name-carrying notation can use reference values to identify the variable bound by a binding term. This approach preserves the simplicity of the name-carrying notation while improving its efficiency. 1 Introduction The λ-calculus (Church, 1941) is used in many theorem provers and automated proof tools. Representing and manipulating λ-terms in such tools is complicated by the need to avoid the name-capture problem which occurs with binding terms and bound variables. A binding term, written λx.t for some name x and λ-term T, denotes an anonymous function and any variable named x occurring in T is bound to that term, to represent the function parameter. Name-capture occurs if there is another term binding x in T : it is unclear to which term variable x is meant to be bound. There are two main approaches to representing λ-terms. The name-carrying notation is that used by Church (1941), its implementation is described by Gordon (1988). In this notation, a variable is represented by its name and name-capture is avoided by ensuring that bound variables are always uniquely named, renaming variables and their binding terms whenever necessary. This approach makes terms easy to examine but difficult to manipulate since renaming involves gathering the names already in use, to ensure that a replacement is unique. The second approach is the namefree notation of de Bruijn (1972). A bound variable is represented by an index giving the number of binding terms between the variable and its binding term, the term λx.λy.x is represented λx.λy.1. Because bound variables are always uniquely associated with their binding term, name-capture does not occur. Implementations of this notation are efficient but complicated by the need to take into account, when examining a term, of the changing indices of a bound variable. This also makes it difficult to treat subterms of a term indepently of the term. The approach to representing λ-terms described here is the name-carrying notation with the names of bound variables represented by the reference values of Standard ML (Milner et al., 1990). A reference is generated by the Standard ML runtime system and is guaranteed to be unique: if two references are created at different times then they are distinct. Terms must still be renamed with this approach but this can be done without testing the newly generated names for uniqueness. This Copyright c 2006 Matthew Wahab 1

2 preserves the simplicity of the name-carrying notation while removing a major source of inefficiency in its implementation. The name-carrying representation using references (which will be called reference-carrying for brevity) will be described through an implementation of the λ-calculus. The features of Standard ML used in the description are summarised in Section 2 and the implementation of the λ-calculus and term representation is given in Section 3. Some practical issues are discussed in Section 4 and Section 5 concludes the paper. 2 Standard ML Milner et al. (1990) give a formal definition of Standard ML. A tutorial description is given by Paulson (1991). Standard ML types include the integers, int, booleans bool, strings, string and the type of n-tuples ( a 1 * * a n ) where a i is a type variable. Expression (e 1,..., e n ) is the n-tuple of expressions e 1,..., e n. The empty list is [] and x::y is the list constructed from element x and list y. Type T 1 is defined as an alias for type T 2 by type T 1 = T 2. An abstract type T is defined datatype T = C 1... C n for n 1 where C i is a constructor for T. If C i is in the form C i of T 1 then it takes an argument of type T 1. An exception e is declared with exception e, thrown with raise e and caught, when it occurs in f, by f handle e => g. Exception Fail s, for string s, is usually used to indicate failure. The conditional expression is if b then e 1 else e 2 for test b and expressions e 1, e 2. The pattern matching expression case f of P 1 => e 1... P n => e n selects e i such that P i is the first pattern (beginning with P 1 ) to match the result of evaluating f. The sequential evaluation of e 1 followed by e 2 is e 1 ; e 2 and returns the result of e 2. Identifier x is defined as the value of expression e by val x =e and a function definition has the form fun f a 1... a n =e where a 1,..., a n are the parameters. Functions can also be defined by pattern matching on the parameters. The anonymous function with argument x and body e is fn x => e. The forms let val x =y in e and let fun f a 1... a n =g in e define variable x and function f respectively as local to expression e. A reference to data item x of type T is created by ref x, has type T ref and!r is x. Type T will be called the base type of type T ref. The assignment of e to reference x is x:=e. Each invocation of function ref creates a unique reference and references can be compared by the equality function =. The expression ref x =ref x is false and the expression let val t=ref x in t=t is true for any x. 3 Implementing the λ-calculus The implementation of the λ-calculus consists of an abstract type representing λ-terms and functions implementing the rules of the calculus. A λ-term is either a free variable which is not bound by a binding term, the application of a term f to term a, fa, a binding term or a bound variable. The rules of the λ-calculus describe conversions defined by textual substitution and the substitution of r for t in T will be written T [r/t]. Renaming is by α-conversion, defined λx.t α λy.t [y/x] where y is a name that doesn t occur in T. An application is reduced by β-conversion, defined (λx.t )E β T [E/x]. The η-conversion of a term is λx.(t x) η T, provided that x doesn t occur in T. The name-capture problem occurs with β-conversion when a binding term with name x is substituted into a term in which x is already bound. For example, if (λy.λx.yx)(λx.x) is reduced to (λx.(λx.x)x), it becomes unclear to which binding term the innermost occurrence of x is bound. 2

3 type binder = string ref fun binder s = ref s fun destbinder q =!q datatype term = Free of string App of term * term Bound of binder Lambda of binder * term fun mem x [] = false mem x (y::ys) = if x=y then true else mem x ys fun isclosedfulltrm sb = case trm of App(f, a) => if (isclosedfull f sb) then (isclosedfull a sb) else false Lambda(q, b) => isclosedfull b (Bound(q)::sb) Bound(q) => mem(bound(q)) sb => true fun isclosed trm = isclosedfull trm [] Figure 1: Representation of λ-terms Terms The reference-carrying representation of λ-terms is given in Figure 1 as the abstract type term. Constructors Free and App represent free variables (which are named with strings) and the application of terms respectively. Constructors Bound and Lambda represent bound variables and binding terms respectively. In both, the name of the bound variable is represented by an element of type binder which is an alias for references to strings. Function binder constructs a unique binder and function destbinder returns the string referred to by a binder. Bound variables are associated with binding terms having the same binder, term Lambda(q, b) binds all terms Bound(q) occurring in b. As with the standard name-carrying notation, binder q of a term Lambda(q, b) must be unique to avoid the name-capture problem. An element T of type term is closed (and represents a well-formed λ-term) if every bound variable Bound(q) in T occurs only as a subterm of a binding term with binder q. Function isclosed tests whether a term T is closed, using function isclosedfull to desc through the structure of T. For each binding term Lambda(q, b), bound variable Bound(q) is added to the (initially empty) list sb. If a bound variable occurring in T does not appear in sb then it must be outside its binding term and T is not closed. Substitution The implementation of substitution given here renames terms each time they are used as replacements, replacing the binder in each binding term Lambda(q, b) and bound variable Bound(q) occuring in b. This is necessary so that, when a substitution T [r/t] is carried out, the binders of binding terms in each instance of r which is substituted into T are unique. 3

4 type substitution = (term * term) list exception NotFound fun add x y sb = (x, y)::sb fun get x [] = raise NotFound get x ((t, r)::ls) = if(x=t) then r else get x ls fun renamefull sb t = case t of Free(s) => Free(s) App(l, r) => App(renameFull sb l, renamefull sb r) Lambda(q, b) => let val nq = binder(destbinder q) in let val nsb = add(bound q) (Bound nq) sb in Lambda(nq, renamefull nsb b) Bound(q) => (get(bound q) sb) handle NotFound => (Bound q) fun rename t = renamefull [] t fun lookup t sb = rename(get t sb) fun subst trm sb = let fun substaux (Free s) = Free s substaux (App(l, r)) = App(subst l sb, subst r sb) substaux (Lambda(q, b)) = Lambda(q, subst b sb) substaux (Bound q) = (Bound q) in (lookup trm sb) handle NotFound => substaux trm Figure 2: Implementation of Substitution The substitution operation is implemented as function subst of Figure 2 using a number of utility types and functions. An element of type substitution stores the list of term-replacement pairs to be used in a substitution. Functions add and get are the basic operations on substitution lists, to respectively add or get a term-replacement pair. Renaming of terms is carried out by function rename, using function renamefull. This descs through a term creating a new, unique binder q for each subterm Lambda(q, b) and replacing bound variable Bound(q) with Bound(q ) in b to obtain a new body b. The subterm is then replaced with Lambda(q, b ). A bound variable appearing outside its binding term is not renamed, allowing the substitution of bound variables for terms. Function lookup is used to get and then rename a replacement term from a substitution list. The expression subst T (add t r []) replaces each occurrence of t in T with a term obtained by renaming r. Because r differs from r only in the binders appearing in binding terms and bound variables, term r is equivalent to r in the λ-calculus (the terms are α-convertible, see Barregt, 1984) and is a valid replacement for t. Function subst is an implementation of textual substitution, any part of a term can be replaced. In the standard name-carrying notation and the namefree notation, substitution is usually specialised 4

5 fun alphaconv (Lambda(q, b)) = let val nq=binder(destbinder q) in Lambda(nq, subst b (add (Bound q) (Bound nq) [])) alphaconv t = raise Fail "Not an alpha-redex" fun betaconv (App(Lambda(q, b), t)) = subst b (add (Bound q) t []) betaconv t = raise Fail "Not a beta-redex" fun etaconv (Lambda(q, App(b, Bound(x)))) = if(q=x) then if(isclosed b) then b else raise Fail "Not an eta-redex" else raise Fail "Not an eta-redex" etaconv t = raise Fail "Not an eta-redex" Figure 3: Implementation of λ-calculus Rules to the replacement of variables, which is all that is needed to define the rules of the λ-calculus (de Bruijn, 1972; Barregt, 1984). To implement the textual substitution T [r/t] in the name-carrying notation, the variable names used in T must be recorded and compared with those occurring in r and those generated when renaming r. Using references, names already in use can be ignored, since reference creation always generates a unique name. In the namefree notation, textual substitution is difficult because of the different indices that represent a bound variable in different parts of a term. For example, the substitution (λx.t )[y/(fx)], where x is inted to be the variable bound by λx.t, involves examining (fx) to identify the occurrences of x and taking into account the changes to the indices of x, as the substitution descs through T, when comparing (fx) with the subterms of T. In a name-carrying notation, only textual equality is needed to compare terms involving bound variables. Rules The rules of the λ-calculus are implemented in terms of the substitution function subst. Function alphaconv carries out α-conversion of the term Lambda(q, b), creating a new binder q and forming a new body b by replacing Bound(q) with Bound(q ) in b to give the new term Lambda(q, b ). Note that function rename provides generalised α-conversion, renaming all binding terms occurring in its argument. Function betaconv implements β-conversion, applied to the term App(Lambda(q, b), t) it substitutes t for Bound(q) wherever it occurs in b. Finally, η-conversion is implemented by function etaconv which, applied to an initially closed term Lambda(q, App(b, Bound(q))), returns b after testing isclosed(b) to ensure that Bound(q) doesn t occur in b. The functions implementing the rules of the λ-calculus always return a closed term if their arguments are closed. Function alphaconv doesn t remove binding terms. Function betaconv collapses a binding term, replacing its bound variable with a given term t. If t is closed then so is the result of betaconv. With function etaconv, both the argument and the result must be closed for the function to succeed. 5

6 fun alphaequals trm1 trm2 = let fun aeql t1 t2 sb = case (t1, t2) of (Free(s1), Free(s2)) => s1=s2 (Bound(b1), Bound(b2)) => let val qv1 = (get t1 sb) handle NotFound => t1 in qv1=t2 (App(f1, a1), App(f2, a2)) => if aeql f1 f2 sb then aeql a1 a2 sb else false (Lambda(q1, b1), Lambda(q2, b2)) => aeql b1 b2 (add (Bound(q1)) (Bound(q2)) sb) => false in aeql trm1 trm2 [] Figure 4: Equality Under α-conversion Comparing Terms In the λ-calculus, terms t 1 and t 2 are considered equivalent if they are equal or can be made equal by renaming bound variables, the terms are α-convertible. In the namefree notation, the equivalence of terms can be determined using textual equality. In name-carrying notations, an α-equality operation must be defined to match bound variables in the two terms. This is implemented as function alphaequals, of Figure 4. The function descs through the structure of terms t 1 and t 2. If binding term λq 1.b 1 in t 1 matches the binding term λq 2.b 2 in t 2, the bound variable Bound(q 1 ) must appear t 1 wherever Bound(q 2 ) appears in t 2, with all other subterms matching exactly. Examples For the examples, the following values will be assumed: val x=binder "x" val y=binder "y" The Standard ML interpreter prints references in terms of their contents which means that it may not be obvious when references are distinct. To make clear the result of operations on terms, function displayrename of Figure 5 is used in the examples to replace the strings referred to by binders. It uses function inttoname to create a string from an integer. For example, the result of evaluating expression displayrename(lambda(x, Bound(x))) is Lambda(ref "a", Bound(ref "a")). α-conversion Renaming with α-conversion constructs a term distinct from its argument. val ac1=lambda(x, (Lambda(y, (App(Bound y, Bound x))))) val ac2=alphaconv ac1 Value ac1 represents the term (λx.λy.yx) and value ac2 is ac1 after renaming. Expression ac1=ac1 is true and ac1=ac2 is false, the terms are distinct under textual equality. The two terms are α-equal, alphaequals ac1 a2 is true. 6

7 fun inttoname i nm= let val numchars = 26 in let val ld = nmˆ(str (chr ((ord #"a")+(i mod numchars)))) and rm = i div numchars in if (rm=0) then ld else inttoname (i-numchars) ld fun displayrenamefull t i sb = case t of (Free( )) => t (App(f, a)) => App(displayRenameFull f i sb, displayrenamefull a i sb) (Bound(q)) => ((get t sb) handle NotFound => t) Lambda(q, b) => let val nq = binder (inttoname (!i) "") in i:=(!i)+1; Lambda(nq, displayrenamefull b i (add (Bound(q)) (Bound(nq)) sb)) fun displayrename t = displayrenamefull t (ref 0) [] Figure 5: Displaying Terms β-conversion β-conversion deps on function subst to ensure that name-capture is avoided. That this happens can be seen by constructing a λ-term, λx.λy.(yx), which is applied to itself: val bc1=lambda(x, (Lambda(y, (App (Bound y, Bound x))))) val bc2=app(bc1, bc1) val bc3=betaconv bc2 Value bc2 represents the term (λx.λy.(yx))(λx.λy.(yx)) and value bc3 is the result of applying β-conversion to reduce bc2 : Lambda(ref "y", App(Bound(ref "y"), Lambda(ref "x", Lambda(ref "y", App(Bound(ref "y"), Bound(ref "x")))))) Although this appears to show that the same binder is used by more than one binding term, evaluating displayrename bc3 makes clear that the bound variables are distinct and represent the term λa.a(λb.λc.(cb)): Lambda(ref "a", App(Bound(ref "a"), Lambda(ref "b", Lambda(ref "c", App(Bound(ref "c"), Bound(ref "b")))))) η-conversion η-conversion removes the outermost binding term if the bound variable is unused. val ec1=lambda(x, App(Lambda(y, Bound(y)), Bound(x))) val ec2=etaconv(ec1) 7

8 Value ec1 represents the term (λx.(λy.y)x) and value ec2 is the η-conversion of ec1, the term (λy.y): Lambda(ref "y", Bound(ref "y")) 4 Practical Issues The approach to representing λ-terms described here deps on the uniqueness of the binders appearing in terms. In a system using the λ-calculus, a term may persist for some time and have several copies. This means that the uniqueness of binders must be maintained as part of the system design, by renaming terms as necessary to ensure that each instance of a term is distinct from any other. This is the reverse of the situation with the namefree notation, where terms can be copied freely. Any type can be used as the base type referred to by binders. With the typed λ-calculus, for example, binders would be references to pairs which record variable names and types. However, a drawback of using references is that they are specific to a particular execution of a program and cannot be used in a subsequent program execution. Instead, translation to and from the namefree notation is necessary to allow terms to be stored for reuse. The main cost of using references is the need to rename terms in which binders occur. In the implementation of substitution given in Figure 2, replacement terms are always renamed and a straightforward optimisation is to test and memoise whether this renaming is necessary. This can be combined with the renaming operation so that that if rename does not make any changes to a term t, a flag is set to prevent a second attempt to rename t. Since the manipulation of terms is mainly carried out in terms of substitution, this optimisation should improve the performance of the term operations. 5 Conclusion Using references as the names in the name-carrying notation provides a representation of λ-terms which is simple to use. The implementation of a term operation can deal with subterms of a term individually while the name-capture problem is avoided by using the Standard ML runtime system to generate unique names. For most term operations, reference-carrying is more efficient than the standard name-carrying notation. An exception is the abstraction from a term T, to give a term λx.t [x/v] where v is a free variable in T. This can be significant for systems such as theorem provers where abstraction is one of the operations used to manipulate terms. In the name-carrying notation, it is enough to construct the abstraction λv.t, without performing the substitution, since free and bound variables have the same representation. In both the namefree notation and the reference-carrying notation, free and bound variables are distinct and the substitution of x for v must be carried out. However, this advantage is offset by the difficulty of maintaining unique names which makes operations involving the structure of a term, such as substitution, complicated and inefficient in the name-carrying notation. Both the namefree and the reference-carrying notation treat a term T as an instance of a set of terms which are equivalent to T. In the namefree notation, term T represents all terms equivalent to T and T is used directly in operations. In the reference-carrying notation, term T is used to generate an equivalent term T and it is T which is used in an operation. The need to generate an equivalent term makes reference-carrying less efficient than the namefree notation. However, a term operation in the namefree notation must take into account the different representations of a bound variable occurring in a term, complicating its implementation. This is avoided in name-carrying notations, including reference-carrying, where a bound variable has the same representation throughout a term. 8

9 The principal benefit of the reference-carrying notation is to preserve the advantages of a namecarrying notation while reducing the cost of manipulating terms. This should lead to term operations which approach the efficiency of those in the namefree notation while being simpler to implement. References Barregt, H. P. (1984). The Lambda Calculus: Its Syntax and Semantics. North-Holland. Church, A. (1941). The Calculi of Lambda Conversion. Princeton University Press. de Bruijn, N. G. (1972). Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation with application to the Church-Rosser theorem. Indagationes Mathematicae 34, Reprinted in: Selected Papers on Automath, edited by R.P. Nederpelt, J.H. Geuvers and R.C. de Vrijer, Studies in Logic, vol. 133, pp North-Holland Gordon, M. J. C. (1988). Progamming Language Theory and its Implementation. Prentice-Hall. Milner, R., Tofte, M. and Harper, R. (1990). The Definition of Standard ML. MIT Press. Paulson, L. C. (1991). ML for the Working Programmer. Cambridge University Press. 9

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

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

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

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

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

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

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

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

λ 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

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

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/ October 13, 2004 Lambda Calculus and Type

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

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

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

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

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

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

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

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

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004 CMPUT 325 : Lambda Calculus Basics Dr. B. Price and Dr. R. Greiner 13th October 2004 Dr. B. Price and Dr. R. Greiner CMPUT 325 : Lambda Calculus Basics 1 Lambda Calculus Lambda calculus serves as a formal

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

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

Demonstrating Lambda Calculus Reduction

Demonstrating Lambda Calculus Reduction Electronic Notes in Theoretical Computer Science 45 (2001) URL: http://www.elsevier.nl/locate/entcs/volume45.html 9 pages Demonstrating Lambda Calculus Reduction Peter Sestoft 1 Department of Mathematics

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

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

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

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

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

Introduction to SML Getting Started

Introduction to SML Getting Started Introduction to SML Getting Started Michael R. Hansen mrh@imm.dtu.dk Informatics and Mathematical Modelling Technical University of Denmark c Michael R. Hansen, Fall 2004 p.1/15 Background Standard Meta

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

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

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

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

Lambda Calculus and Extensions as Foundation of Functional Programming

Lambda Calculus and Extensions as Foundation of Functional Programming 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 Overview

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

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

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

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II) Processadors de Llenguatge II Functional Paradigm Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Paradigm Shift Imperative Paradigm State Machine

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

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

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

CSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point

CSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point Lambda Calculus CSE 505 Lecture #9 October 1, 2012 Expr ::= Var λ Var. Expr (Expr Expr) Key Concepts: Bound and Free Occurrences Substitution, Reduction Rules: α, β, η Confluence and Unique Normal Form

More information

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Why study? Lambda calculus Syntax Evaluation Relationship to programming languages Church Rosser theorem Completeness of Lambda Calculus: Turing

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

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

Fall Lecture 3 September 4. Stephen Brookes

Fall Lecture 3 September 4. Stephen Brookes 15-150 Fall 2018 Lecture 3 September 4 Stephen Brookes Today A brief remark about equality types Using patterns Specifying what a function does equality in ML e1 = e2 Only for expressions whose type is

More information

(Refer Slide Time: 4:00)

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

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

More Untyped Lambda Calculus & Simply Typed Lambda Calculus Concepts in Programming Languages Recitation 6: More Untyped Lambda Calculus & Simply Typed Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky,

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

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

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

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

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

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples: COMP80 Programming Languages Slides Courtesy of Prof. Sam Guyer Lambda Calculus Formal system with three parts Notation for functions Proof system for equations Calculation rules called reduction Idea:

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

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming

More information

Higher-Order Logic. Specification and Verification with Higher-Order Logic

Higher-Order Logic. Specification and Verification with Higher-Order Logic Higher-Order Logic Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter (Slides by Jens Brandt) Software Technology Group Fachbereich Informatik Technische Universität Kaiserslautern

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

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions CVO103: Programming Languages Lecture 5 Design and Implementation of PLs (1) Expressions Hakjoo Oh 2018 Spring Hakjoo Oh CVO103 2018 Spring, Lecture 5 April 3, 2018 1 / 23 Plan Part 1 (Preliminaries):

More information

Lecture 2: Big-Step Semantics

Lecture 2: Big-Step Semantics Lecture 2: Big-Step Semantics 1 Representing Abstract Syntax These are examples of arithmetic expressions: 2 * 4 1 + 2 + 3 5 * 4 * 2 1 + 2 * 3 We all know how to evaluate these expressions in our heads.

More information

CSE-321 Programming Languages 2012 Midterm

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

CSE-321 Programming Languages 2010 Midterm

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

Lambda Calculus.

Lambda Calculus. Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto, Stephen A. Edwards) Benjamin Pierce Types and Programming Languages http://www.cs.cornell.edu/courses/cs3110/2008fa/recitations/rec26.html

More information

What does my program mean?

What does my program mean? September 16, 2015 L02-1 What does my program mean? Armando Solar Lezama Computer Science and Artificial Intelligence Laboratory M.I.T. Adapted from Arvind 2010. Used with permission. September 16, 2015

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. Adrian Groza. Department of Computer Science Technical University of Cluj-Napoca

Lambda Calculus. Adrian Groza. Department of Computer Science Technical University of Cluj-Napoca Lambda Calculus Adrian Groza Department of Computer Science Technical University of Cluj-Napoca Outline 1 λ-calculus 2 Operational Semantics Syntax Conversions Normal Form 3 Lambda Calculus as a Functional

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

CS152: 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 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 information

Introduction to the Lambda Calculus. Chris Lomont

Introduction to the Lambda Calculus. Chris Lomont Introduction to the Lambda Calculus Chris Lomont 2010 2011 2012 www.lomont.org Leibniz (1646-1716) Create a universal language in which all possible problems can be stated Find a decision method to solve

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

Programming Languages Lecture 14: Sum, Product, Recursive Types

Programming 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

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

Functional Programming. Functional Programming

Functional Programming. Functional Programming 2014-06-27 Functional Programming Functional Programming 2014-06-27 Functional Programming 1 Imperative versus Functional Languages attributes of imperative languages: variables, destructive assignment,

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information

CSE-321 Programming Languages 2010 Final

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

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

Part I. Historical Origins

Part I. Historical Origins Introduction to the λ-calculus Part I CS 209 - Functional Programming Dr. Greg Lavender Department of Computer Science Stanford University Historical Origins Foundations of Mathematics (1879-1936) Paradoxes

More information

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

Lecture Notes on Data Representation

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

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

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

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1 LAMBDA CALCULUS 1. Background λ-calculus is a formal system with a variety of applications in mathematics, logic, and computer science. It examines the concept of functions as processes, rather than the

More information

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML) CIS24 Project #3 Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec Subject: Functional Programming Language (ML) 1 Introduction ML Programming Language Functional programming

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

Lecture 9: More Lambda Calculus / Types

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

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

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

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

Variables. Substitution

Variables. Substitution Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

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

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1 A Third Look At ML Chapter Nine Modern Programming Languages, 2nd ed. 1 Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order

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

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

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