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.

- 159 -SQUARE 1 => ... =>IFIND 1 SQUARES => ... =>IFIND 0 (TAIL SQUARES) => ... =>HEAD (TAIL SQUARES) ==HEAD (TAIL ((SQ 0)::(SQ 1) 9::4::(SQLIST (SUCC 2)))) -> ... ->HEAD ((SQ 1) 9::4::(SQLIST (SUCC 2))) => ... =>(SQ 1) 9=> ... => 1which replaces all occurrences of bound pair 9 so SQUARES is now:(SQ 0)::1::4::(SQLIST (SUCC 2))Thus, repeated list access evaluates more and more of the infinite list but avoids repetitive evaluation.Lazy evaluation is used for Miranda lists.8.10. SummaryIn this chapter we have:• compared normal and applicative order β reduction and seen that normal order reduction may be less efficient• seen that consitent applicative order β reduction with our conditional expression representation leads <strong>to</strong> nontermination• considered ways of delaying applicative order evaluation• seen that the halting problem is unsolvable• met the Church-Rosser theorems which suggest that normal order β reduction is most likely <strong>to</strong> terminate• seen that normal order β reduction enables the construction of infinite objects• met lazy evaluation as a way of combining the best aspects of normal and applicative order β reductionLazy evaluation is summarised below.Lazy evaluationi) number every bound pairii)To lazy evaluate ( ) ia) lazy evaluate <strong>to</strong> b) if is λ.then replace all free occurences of in with and renumber consistently all surrounding bound pairsand replace all occurences of ( ) iwith the new and lazy evaluate the new

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

Saved successfully!

Ooh no, something went wrong!