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.

- 14 -We have made a function from a formula by replacing an object with a name and identifying the name that we used.We have then evaluated the function by replacing the name in the formula with a new object and evaluating theresulting formula.Let us use abstraction again <strong>to</strong> generalise our example further. Suppose the cost of items goes up <strong>to</strong> 11 pence. Nowthe <strong>to</strong>tal cost of items is:REPLACE items IN 11*itemsSuppose the cost of items drops <strong>to</strong> 9 pence. Now the <strong>to</strong>tal cost of items is:REPLACE items IN 9*itemsBecause the cost changes, we could also introduce a name <strong>to</strong> stand for the cost in general, say cost:REPLACE cost INREPLACE items IN cost*itemsHere we have abstracted over two operands in the formula. To evaluate the abstraction we need <strong>to</strong> supply two values.For example, 12 items at 32 pence will have <strong>to</strong>tal cost:which is:which is:REPLACE cost WITH 32 INREPLACE items WITH 12 IN cost*itemsREPLACE items WITH 12 IN 32*items32*12For example, 25 items at 15 pence will have <strong>to</strong>tal cost:which is:which is:REPLACE cost WITH 15 INREPLACE items WITH 25 IN cost*itemsREPLACE items WITH 25 IN 15*items15*25Suppose we now want <strong>to</strong> solve a different problem. We are given the <strong>to</strong>tal cost and the number of items and we want<strong>to</strong> find out how much each item costs. For example, if 12 items cost 144 pence then each item costs:144/12If 15 items cost 45 pence then each item costs:45/12In general, if items items cost cost pence then each item costs:REPLACE cost INREPLACE items IN cost/items

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

Saved successfully!

Ooh no, something went wrong!