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.

- 128 -[[,],,] ==(::::NIL)::::::NILso:F == S == A bound variable list of the form:[N,A,P]::Tcan be used <strong>to</strong> match a direc<strong>to</strong>ry so [N,A,P] matches the first entry and T matches the rest of the direc<strong>to</strong>ry. Forexample, we might sort the direc<strong>to</strong>ry in telephone number order using the insertion sort from chapter 7:rec DINSERT R [] = [R]or DINSERT [N1,A1,P1] ([N2,A2,P2]::T) =IF LESS P1 P2THEN [N1,A1,P1]::[N2,A2,P2]::TELSE [N2,A2,P2]::(DINSERT [N1,A1,P1] T)rec DSORT [] = []or DSORT (H::T) = DINSERT H (DSORT T)7.6. Local definitionsIt is often useful <strong>to</strong> introduce new name/value associations for use within an expression. Such associations are said <strong>to</strong>be local <strong>to</strong> the expression and are introduced by local definitions. Two forms of local definition are used in functionalprogramming and they are both equivalent <strong>to</strong> function application.Consider:λ. This requires the replacement of all free occurences of in with before isevaluated.Alternatively, and might be thought of as being associated throughout the evaluation of. This might be written in a bot<strong>to</strong>m up style as:let = in or in a <strong>to</strong>p down style as:where = We will use the bot<strong>to</strong>m up let form of local definition on the grounds that things should be defined before they areused.7.7. Matching composite value resultsThe use of bound variable lists greatly simplifies the construction of functions which return composite value resultsrepresented as lists.

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

Saved successfully!

Ooh no, something went wrong!