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.

- 121 -["Betty","Baker"].For example, we might represent a s<strong>to</strong>ck item consisting of a string , an integer and an integer as the list:[,,]for example:or["VDU",25,10]["modem",12,15].For example, we might represent a telephone direc<strong>to</strong>ry entry consisting of a composite value name as above, a string and an integer as a list:[[,],,]for example:or[["<strong>An</strong>na","Able"],"Accounts",1212][["Betty","Baker"],"Boiler room",4242]Now, a sequence of composite values will be represented by a list of lists, for example a circulation list:[["<strong>An</strong>na","Able"],["Betty","Baker"],["Clarice","Charlie"]]or a s<strong>to</strong>ck list:[["VDU",25,10],["modem",12,15],["printer,250,7]]or a telephone direc<strong>to</strong>ry:[[["<strong>An</strong>na","Able"],"Accounts",1212],[["Betty","Baker"],"Boiler room",4242],[["Clarice","Charlie"],"Cus<strong>to</strong>mer orders",1234]]7.3. Processing composite values sequencesWe are using linear lists <strong>to</strong> represent composite value sequences so we will now look at the use of linear listalgorithms <strong>to</strong> process them.For example, suppose that given a circulation list we want <strong>to</strong> find someone’s forename from their surname. If the listis empty then return the empty list. If the list is not empty then if the surname matches that for the first name in the listthen return the corresponding forename. Otherwise, try looking in the rest of the list.rec NFIND S [] = []or NFIND S (H::T) =

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

Saved successfully!

Ooh no, something went wrong!