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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- 31 -(λx.x λx.x) =>λx.xIt is possible, however, for bound variables in different functions <strong>to</strong> have the same name. Consider:(λf.(f λf.f) λs.(s s))This should give the same result as the previous expression. Here, the bound variable f should be replaced by:λs.(s s)Note that we should replace the first f in:(f λf.f)but not the f in the body of:λf.fThis is a new function with a new bound variable which just happens <strong>to</strong> have the same name as a previous boundvariable.To clarify this we need <strong>to</strong> be more specific about how bound variables relate <strong>to</strong> variables in function bodies. For anarbitrary function:λ.the bound variable may correspond <strong>to</strong> occurrences of in and nowhere else. Formally, thescope of the bound variable is .For example, in:λf.λs.(f (s s))the bound variable f is in scope in:In:λs.(f (s s))(λf.λg.λa.(f (g a)) λg.(g g))the leftmost bound variable f is in scope in:λg.λa.(f (g a))and nowhere else. Similarly, the rightmost bound variable g is in scope in:(g g)and nowhere else.Note that we have said may correspond. This is because the re-use of a name may alter a bound variable’s scope, aswe will see.Now we can introduce the idea of a variable being bound or free in an expression. A variable is said <strong>to</strong> be bound <strong>to</strong>occurrences in the body of a function for which it is the bound variable provided no other functions within the body

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

Saved successfully!

Ooh no, something went wrong!