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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- 77 -def ISBOOL B = MAKE_BOOL (isbool B)5.8. Numbers and arithmeticWe will represent the number type as two:def numb_type = twoand a number will be a pair starting with numb_type:def MAKE_NUMB = make_obj numb_typeMAKE_NUMBs definition expands <strong>to</strong>:λvalue.λs.(s numb_type value)We need an error object for arithmetic type errors:def NUMB_ERROR = MAKE_ERROR numb_typewhich expands <strong>to</strong>:λs.(s error_type numb_type)We also need a type tester:def isnumb = istype numb_typewhich expands <strong>to</strong>:λobj.(equal (type obj) numb_type)from which we can define a typed type tester:def ISNUMB N = MAKE_BOOL (isnumb N)Next we can construct a typed zero:def 0 = MAKE_NUMB zerowhich expands as:λs.(s numb_type zero)We now need a typed successor function:def SUCC N =if isnumb Nthen MAKE_NUMB (succ (value N))else NUMB_ERROR<strong>to</strong> define numbers:def 1 = SUCC 0def 2 = SUCC 1

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

Saved successfully!

Ooh no, something went wrong!