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.

- 60 -add three ((λx.λy.if iszero ythen zeroelse add x ((λs.(mult1 (s s)) λs.(mult1 (s s)))x (pred y))) three (pred two)) -> ... ->add three if iszero (pred two)then zeroelse add three ((λs.(mult1 (s s)) λs.(mult1 (s s)))three (pred (pred two))) -> ... ->add three (add three ((λs.(mult1 (s s)) λs.(mult1 (s s)))three (pred (pred two)))) ->add three (add three (mult1 (λs.(mult1 (s s)) λs.(mult1 (s s)))three (pred (pred two)))) ==add three (add three ((λx.λy.if iszero ythen zeroelse add x ((λs.(mult1 (s s)) λs.(mult1 (s s)))x (pred y))three (pred (pred two)))) -> ... ->add three (add three if iszero (pred (pred two))then zeroelse add three ((λs.(mult1 (s s)) λs.(mult1 (s s)))three (pred (pred (pred two))))) -> ... ->add three (add three zero) -> ... ->add three three => ... =>six4.7. Recursion notationThe function recursive is known as a paradoxical combina<strong>to</strong>r or a fixed point finder, and is called Y in the λcalculus literature.Rather than always defining an auxiliary function with an abstraction and then using recursive <strong>to</strong> construct arecursive version, we will allow the defined name <strong>to</strong> appear in the defining expression but use a new definition form:rec = This is <strong>to</strong> indicate that the occurrence of the name in the definition should be replaced using abstraction and theparadoxical combina<strong>to</strong>r should then be applied <strong>to</strong> the whole of the defining expression. For example, for addition, wewill write:instead of:rec add x y =if iszero ythen xelse add (succ x) (pred y)

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

Saved successfully!

Ooh no, something went wrong!