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.

- 138 -[["Mark","Monkey"],[["Graham","Goat"],[["David","Duck"],EMPTY,EMPTY],[["James","Jaguar"],EMPTY,EMPTY]],[["Quentin","Quail"],EMPTY,EMPTY]]The tree traversal function above may be applied <strong>to</strong> binary trees with arbitrary node values as it only inspects branchesduring traversal. For example:TRAVERSE [["Mark","Monkey"],[["Graham","Goat"],[["David","Duck"],EMPTY,EMPTY],[["James","Jaguar"],EMPTY,EMPTY]],[["Quentin","Quail"],EMPTY,EMPTY]] -> ... ->[["David","Duck"],["Graham","Goat"],["James","Jaguar"],["Mark","Monkey"],["Quentin","Quail"]]Finally, the tree search function above may be modified <strong>to</strong> return some or all of a required composite value. Forexample, we might find the forename corresponding <strong>to</strong> a surname, using the surname <strong>to</strong> identify the required node:rec CTFIND S EMPTY = ""or CTFIND S [[NF,NS],L,R] =IF STRING_EQUAL S NSTHEN NFELSEIF STRING_LESS S NSTHEN CTFIND S LELSE CTFIND S RFor example:CTFIND "Duck" [["Mark","Monkey"],[["Graham","Goat"],[["David","Duck"],EMPTY,EMPTY],[["James","Jaguar"],EMPTY,EMPTY]],[["Quentin","Quail"],EMPTY,EMPTY]] -> ... ->CTFIND "Duck" [["Graham","Goat"],[["David","Duck"],EMPTY,EMPTY],[["James","Jaguar"],EMPTY,EMPTY]] -> ... ->CTFIND "Duck" [["David","Duck"],EMPTY,EMPTY]"David"

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

Saved successfully!

Ooh no, something went wrong!