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.

- 158 -(SQLIST (SUCC (SUCC 0) 1) 3) 4=> ... =>(SQ (SUCC (SUCC 0) 1) 3) 6::(SQLIST (SUCC (SUCC (SUCC 0) 1) 3) 7) 8Occurrences of bound pair 4 are replaced by the new bound pair 8 so SQUARES is now:(SQ 0)::(SQ (SUCC 0) 1)::(SQ (SUCC (SUCC 0) 1) 3) 6::(SQLIST (SUCC (SUCC (SUCC 0) 1) 3) 7) 8Thus, evaluation of:HEAD (TAIL (TAIL SQUARES))requires the selection of:(SQ (SUCC (SUCC 0) 1) 3) 6This requires the evaluation of:(SUCC (SUCC 0) 1) 3which in turn requires the evaluation of:(SUCC 0) 1=> ... => 1which replaces all occurrences of bound pair 1. Now, SQUARES is:(SQ 0)::(SQ 1)::(SQ (SUCC 1) 3) 6::(SQLIST (SUCC (SUCC 1) 3) 7) 8Thus evaluation of:(SUCC (SUCC 0) 1) 3=> ... =>(SUCC 1) 3gives:2which replaces all occurrences of bound pair 3 so SQUARES is now:(SQ 0)::(SQ 1)::(SQ 2) 6::(SQLIST (SUCC 2) 7) 8Finally, evaluation of:(SQ 2) 6gives:4which replaces all occurrences of bound pair 6 so SQUARES is now:(SQ 0)::(SQ 1)::4::(SQLIST (SUCC 2))If we now try:

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

Saved successfully!

Ooh no, something went wrong!