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.

- 83 -will do so. However, for a non numeric argument, ISZERO (and thence the two IFs) will return a BOOL_ERRORinstead of a NUMB_ERROR.As definitions these seem satisfac<strong>to</strong>ry but they would be appallingly inefficient if used as the basis of animplementation because of repetitive type checking. Consider, for example(*):ADD 1 2First of all in:both:and:IF AND (ISNUMB 1) (ISNUMB 2)ISNUMB 1ISNUMB 2are checked and return booleans. Next:AND (ISNUMB 1) (ISNUMB 2)checks that both ISNUMBs return booleans and then itself returns a boolean. Then:IF AND (ISNUMB 1) (ISNUMB 2)checks that AND returns a boolean.Secondly, after ADD1 is called:calls:IF ISZERO 2ISZERO 2<strong>to</strong> check that 2 is a number and return a boolean. Next:IF ISZERO 2checks that ISZERO returns a boolean.Now, ADD1 is called recursively through:so:calls:ADD1 (SUCC 1) (PRED 2)IF ISZERO (PRED 2)________________________________________________(*) This example also highlights repetitive argument evaluation due <strong>to</strong> naive normal order evaluation. We will consider differentapproaches <strong>to</strong> argument evaluation in chapter 8.

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

Saved successfully!

Ooh no, something went wrong!