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.

- 142 -<strong>to</strong>:.7.16. Partial applicationWe have been using a technique which is known as partial application where a multi-parameter function is used <strong>to</strong>construct another multi-parameter function by providing arguments for only some of the parameters. We have takenthis for granted because we use nested single bound variable functions. For example, in chapter 5 we defined thefunction:def istype t obj = equal t (type obj)<strong>to</strong> test an objects type against an arbitrary type t and then constructed:def isbool = istype bool_typedef isnumb = istype numb_typedef ischar = istype char_typedef islist = istype list_type<strong>to</strong> test whether an object was a boolean, number, character or list by ‘filling in’ the bound variable t with anappropriate argument. This creates no problems for us because istype is a function of one bound variable whichreturns a function of one bound variable. However, many imperative languages with multi-parameter procedures andfunctions do not usually allow procedures and functions as objects in their own right, (POP-2 and PS-algol areexceptions), and so partial application is not directly available. However, an equivalent form is based on defining anew function or procedure with less parameters which calls the original procedure or function with some of itsparameters ‘filled in’.For example, had istype been defined in Pascal as:FUNCTION ISTYPE(T:TYPEVAL,OBJ:OBJECT):BOOLEANBEGINISTYPE := (T = TYPE(OBJ))END,assuming that Pascal allowed the construction of appropriate types, then ISBOOL might be defined by:FUNCTION ISBOOL(O:OBJECT):BOOLEANBEGINISBOOL := ISTYPE(BOOL_TYPE,O)ENDandISNUMBby:FUNCTION ISNUMB(OBJ:OBJECT):BOOLEANBEGINISNUMB := ISTYPE(NUMB_TYPE,OBJ)ENDand so on. In our notation, it is as if we had defined:

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

Saved successfully!

Ooh no, something went wrong!