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.

- 116 -which is equivalent <strong>to</strong> the original:because:rec DOUBLE [] = []or DOUBLE (H::T) = (2*H)::(DOUBLE T)DOUBLE == MAPCAR λX.(2*X)For example:DOUBLE [1,2,3] => ... =>(λX.(2*X) 1):)::(MAPCAR λX.(2*X) [2,3]) -> ... ->2::(λX.(2*X) 2)::(MAPCAR λX.(2*X) [3]) -> ... ->2::4::(λX.(2*X) 3)::(MAPCAR λX.(2*X) []) -> ... ->2::4::6::[] ==[2,4,6]Similarly, we can redefine PLURAL as:def PLURAL = MAPCAR λW.(APPEND W "s")so expanding the definition gives:rec PLURAL [] = []or PLURAL (H::T) = (λW.(APPEND W "s") H)::(MAPCAR λW.(APPEND W "s") T)so, simplifying:def PLURAL [] = []or PLURAL (H::T) = (APPEND H "s")::(MAPCAR λW.(APPEND W "s") T)which is equivalent <strong>to</strong>:because:rec PLURAL [] = []or PLURAL (H::T) = (APPEND H "s")::(PLURAL T)PLURAL == MAPCAR λW.(APPEND W "s")For example:PLURAL ["cat","dog","pig"] => ... =>(λW.(APPEND W "s") "cat")::(MAPCAR λW.(APPEND W "s") ["dog","pig"]) -> ... ->"cats"::(λW.(APPEND W "s") "dog")::(MAPCAR λW.(APPEND W "s") ["pig"]) -> ... ->

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

Saved successfully!

Ooh no, something went wrong!