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.

- 100 -Note that the comparison depends on the type of the list elements.Suppose we are deleting from a linear list of numbers. For example, suppose we want <strong>to</strong> delete 3from the list:we use:[1,2,3,4]DELETE 3 [1,2,3,4] -> ... ->CONS 1 (DELETE 3 [2,3,4]) -> ... ->CONS 1 (CONS 2 (DELETE 3 [3,4])) -> ... ->CONS 1 (CONS 2 [4]) -> ... ->CONS 1 [2,4] ==[1,2,4]In our notation, the function becomes:rec DELETE V L =IF ISNIL LTHEN NILELSEIF EQUAL V (HEAD L)THEN TAIL LELSE (HEAD L)::(DELETE V (TAIL L))For example, suppose we want <strong>to</strong> delete 10 from:we use:[5,10,15,20]DELETE 10 [5,10,15,20](HEAD [5,10,15,20])::(DELETE 10 (TAIL [5,10,15,20])) -> ... ->5::(DELETE 10 ([10,15,20]))5::(TAIL [10,15,20]) -> ... ->5::[15,20] => ... =>[5,15,20]Note again that implicit list head and tail selection in the case notation ie replaced by explicit selection in our currentnotation.6.9. List comparisonTwo lists are the same if they are both empty:

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

Saved successfully!

Ooh no, something went wrong!