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.

- 78 -def 3 = SUCC 2etc.For example, 1 expands as:First of all:SUCC 0 => ... =>if isnumb 0then MAKE_NUMB (succ (value N))else NUMB_ERRORisnumb 0 ==equal (type 0) numb_type ==equal (λobj.(obj select_first) 0) numb_type =>equal (0 select_first) numb_type ==equal (λs.(s numb_type zero) select_first) numb_type -> ... ->equal numb_type numb_type => ... =>trueThus, we next evaluate:MAKE_NUMB (succ (value 0)) ==MAKE_NUMB (succ (λobj.(obj select_second) 0)) ->MAKE_NUMB (succ (0 select_second)) ==MAKE_NUMB (succ (λs.(s numb_type zero) select_second) -> ... ->MAKE_NUMB (succ zero) ==MAKE_NUMB one ==λvalue.λs.(s numb_type value) one =>λs.(s numb_type one)In general, a typed number is a pair with the untyped equivalent as value.We can now redefine the predecessor function <strong>to</strong> return an error for zero:def PRED N =if isnumb Nthenif iszero (value N)then NUMB_ERRORelse MAKE_NUMB ((value N) select_second)else NUMB_ERROR

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

Saved successfully!

Ooh no, something went wrong!