10.07.2015 Views

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

- 32 -introduce the same bound variable. Otherwise it is said <strong>to</strong> be free.Thus, in the expression:λx.xthe variable x is bound but in the expression:xthe variable x is free. In:λf.(f λx.x)the variable f is bound but in the expression:(f λx.x)the variable f is free.In general, for a function:λ. refers <strong>to</strong> the same variable throughout except where another function has as its boundvariable. References <strong>to</strong> in the new function’s body then correspond <strong>to</strong> the new bound variable and not theold.In formal terms, all the free occurrences of in are references <strong>to</strong> the same bound variable introduced by the original function. is in scope in wherever it may occur free; that is except whereanother function introduces it in in a new scope.For example, in the body of:which is:λf.(f λf.f)(f λf.f)the first f is free so it corresponds <strong>to</strong> the original bound variable f but subsequent fs are bound and so are distinctfrom the original bound variable. The outer f is in scope except in the scope of the inner f.In the body of:which is:λg.((g λh.(h (g λh.(h λg.(h g))))) g)(g λh.(h (g λh.(h λg.(h g))))) gthe first, second and last occurrences of g occur free so they correspond <strong>to</strong> the outer bound variable g. The third andfourth gs are bound and so are distinct from the original g. The outer g is in scope in the body except in the scope ofthe inner g.Let us tighten up our definitions. A variable is bound in an expression if:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!