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.

- 76 -TRUE select_second ==λs.(s bool_type true) select_second => ... =>trueand:value FALSE => ... =>falseso:MAKE_BOOL (and (value TRUE) (value FALSE)) ->MAKE_BOOL (and true (value FALSE)) ->MAKE_BOOL (and true false) ->MAKE_BOOL false ==λvalue.λs.(s bool_type value) false =>λs.(s bool_type false) ==FALSE5.7. Typed conditional expressionWe need a typed conditional expression <strong>to</strong> handle both typed booleans and type errors in a condition:def COND E1 E2 C =if isbool Cthenif value Cthen E1else E2else BOOL_ERRORNote that this typed conditional function will return BOOL_ERROR if the condition is not a boolean.We will now write:instead of:IF THEN ELSE COND We also need typed versions of the type testers for use with IF because iserror and isbool return the untypedtrue or false instead of the typed TRUE or FALSE:def ISERROR E = MAKE_BOOL (iserror E)

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

Saved successfully!

Ooh no, something went wrong!