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.

- 40 -((λe1.λe2.λc.((c e1) e2) ) ) =>(λe2.λc.((c ) e2) ) =>λc.((c ) )Now, if this function is applied <strong>to</strong> select_first:(λc.((c ) ) select_first) =>((select_first ) ) => ... =>and if it is applied <strong>to</strong> select_second:(λc.((c ) ) select_second) =>((select_second ) ) => ... =>Notice that the is the last argument for cond, not the first.Now, we will use the conditional expression and cond function with:def true = select_firstdef false = select_second<strong>to</strong> model some of the logical opera<strong>to</strong>rs.3.3. NOTNOT is a unary opera<strong>to</strong>r of the form:NOT which we will describe through a truth table with X standing for the single operand:X | NOT X------+------FALSE | TRUETRUE | FALSENote that if the operand is TRUE then the answer is FALSE and if the operand is FALSE then the answer is TRUE.Thus NOT could be written using an conditional expression as:X ? FALSE : TRUEWe can describe this using selec<strong>to</strong>rs so if the operand is TRUE then FALSE is selected and if the operand is FALSEthen TRUE is selected. This suggests using:def not = λx.(((cond false) true) x)Simplifying the inner body gives:

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

Saved successfully!

Ooh no, something went wrong!