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.

- 13 -To begin with, we will briefly discuss abstraction as generalisation through the introduction of names in expressionsand specialisation through the replacement of names with values. We will also consider the role of abstraction inprogramming languages.Next we will take an overview of the λ calculus as a system for abstractions based on functions and functionapplications. We will discuss informally the rules for constructing and evaluating λ expressions in some detail.We will introduce a notation for defining named functions and look at how functions may be constructed from otherfunctions.We will then consider functions for manipulating pairs of values. These will be used as building blocks in subsequentchapters <strong>to</strong> add syntax for booleans, numbers, types and lists <strong>to</strong> λ calculus.Lastly, we will take a slightly more formal look at λ expression evaluation.2.2. AbstractionAbstraction is central <strong>to</strong> problem solving and programming. It involves generalisation from concrete instances of aproblem so that a general solution may be formulated. A general, abstract, solution may then be used in turn <strong>to</strong> solveparticular, concrete instances of the problem.The simplest way <strong>to</strong> specify an instance of a problem is in terms of particular concrete operations on particularconcrete objects. Abstraction is based on the use of names <strong>to</strong> stand for concrete objects and operations <strong>to</strong> generalisethe instances. A generalised instance may subsequently be turned in<strong>to</strong> a particular instance by replacing the nameswith new concrete objects and operations.We will try <strong>to</strong> get a feel for abstraction through a somewhat contrived example. Consider buying 9 items at 10 penceeach. The <strong>to</strong>tal cost is:10*9Here we are carrying out the concrete operation of multiplication on the concrete values 10 and 9. Nowconsider buying 11 items at 10 pence each. The <strong>to</strong>tal cost is:10*11Here we are carrying out the concrete operation of multiplication on the concrete values 10 and 11.We can see that as the number of items changes so the formula for the <strong>to</strong>tal cost changes at the place where thenumber of items appears. We can abstract over the number of items in the formula by introducing a name <strong>to</strong> standfor a general number of items, say items:10*itemsWe might make this abstraction explicit by preceding the formula with the name used for abstraction:REPLACE items IN 10*itemsHere, we have abstracted over an operand in the formula. To evaluate this abstraction we need <strong>to</strong> supply a value forthe name. For example, for 84 items:REPLACE items WITH 84 IN 10*itemswhich gives:10*84

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

Saved successfully!

Ooh no, something went wrong!