Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Falcon (programming language) wikipedia , lookup
Standard ML wikipedia , lookup
Anonymous function wikipedia , lookup
Curry–Howard correspondence wikipedia , lookup
Closure (computer programming) wikipedia , lookup
Combinatory logic wikipedia , lookup
Lambda calculus wikipedia , lookup
Introduction • A λ – expression specifies the: The λ – Calculus – Parameters of a function – Definition of a function • A λ – expression is of the form: Joseph Spring 7COM1023 Programming Paradigms (A. B. Tucker & R. E. Noonan, Programming Languages: Principles and Paradigms, 2nd Ed, McGraw Hill, 2007) ( x x x ) (parameter/identifier definition) • Note: A λ – expression does NOT specify the name of a function 1 Discussion Points • • • • • • 4 Expressions • So given a function Introduction Expressions Bound and Free Variables Substitution Beta Reduction Eager and Lazy Evaluation Square : by x x x So Square( x) x x the corresponding lambda expression would be ( x x x) • An instance of a lambda expression to a particular value ‘a’ takes the form: (( x x x) a) a a a 2 • So, for example: (( x x x)3) 3 3 9 2 Introduction 5 Pure / Uninterpreted Lambda Calculus Definition (Church) 1. An identifier is a lambda expression e.g. x (λx x) 2. Given two lambda expressions M and N the application of M to N is also a lambda expression and is denoted by (M N) • The λ – Calculus is said to be: – Developed by Alonzo Church in 1941 – ‘The foundation of functional programming’ which was developed in the early 1960’s • A λ – expression specifies the: – Parameters of a function – Definition of a function e.g. ((λx x) (λy y)) • A λ – expression does NOT specify the name of a function 3 6 1 Pure / Uninterpreted Lambda Calculus Substitution Substituting an expression N for a variable x in M is denoted by M[x N] and defined as follows: Definition (Church) 3. An abstraction, written as ( x M) with x an identifier and M a lambda expression is also a lambda expression 1. If the free variables of N have no bound occurrences in M, then the term M[x N] is formed by replacing all free occurrences of x in M by N. Otherwise: In terms of the BNF grammar rules: LambdaExpression variable| (M N) | ( x M) M LambdaExpression N LambdaExpression 2. Assume that the variable y is free in N and bound in M. Then consistently replace the binding and corresponding bound occurrences of y in M, by a new variable, say u. Repeat until the condition in 1. above applies. Then proceed as in step 1. 7 Bound and Free Variables 10 Substitution - Examples Definition (Church) 1. Given a lambda expression ( x M) the variable x is said to be bound in the sub-expression M 2. A bound variable is one whose name is the same as the parameter. Otherwise the variable is said to be free 3. Any variable not bound in M is said to be free Note: bound variables are placeholders just like function parameters in the imperative and OOP paradigms x[ x y ] y (xx)[ x y ] ( yy ) (zw)[ x y ] ( zw) (zx)[ x y ] ( zy ) ( x ( z x))[ x y] (u ( zu))[ x y] (u ( zu)) ( x ( z x))[y x] (u ( zu))[y x] (u ( zu)) 8 Renaming Variables 11 Reference Any such variable can be renamed in a consistent manner with any variable free in M, without changing the meaning of the lambda expression Free variables can be defined in a lambda expression as: free( x) x 1. A. B. Tucker & R. E. Noonan, Programming Languages: Principles and Paradigms, 2nd Ed, McGraw Hill, 2007 2. M. Gabrielli & S. Martini, Programming Languages: Principles and Paradigms, Springer, 2010 3. H. E. Bal & D. Grune, Programming Language Essentials, Addison Wesley, 1994 free( MN ) free( M ) free( N ) free( x M ) free( M ) \{x} free( M ) {x} 9 12 2