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.

- 234 -iii) rec DTRAVERSE TEMPTY = []or DTRAVERSE [V,L,R] = APPEND (DTRAVERSE R) (V::(DTRAVERSE L))3)rec EVAL [E1,OP,E2] =let R1 = EVAL E1inlet R2 = EVAL E2inIF STRING_EQUAL OP "+"THEN R1 + R2ELSEIF STRING_EQUAL OP "-"THEN R1 - R2ELSEIF STRING_EQUAL OP "*"THEN R1 * R2ELSE R1 / R2or EVAL N = NChapter 81)i)Normal orderλs.(s s) (λf.λa.(f a) λx.x λy.y) =>(λf.λa.(f a) λx.x λy.y) (λf.λa.(f a) λx.x λy.y) =>(λa.(λx.x a) λy.y) (λf.λa.(f a) λx.x λy.y) =>(λx.x λy.y) (λf.λa.(f a) λx.x λy.y) =>λy.y (λf.λa.(f a) λx.x λy.y) =>λf.λa.(f a) λx.x λy.y =>λa.(λx.x a) λy.y =>λx.x λy.y =>λy.y8 reductionsλf.λa.(f a) λx.x λy.y reduced twiceApplicative orderλs.(s s) (λf.λa.(f a) λx.x λy.y) ->λs.(s s) (λa.(λx.x a) λy.y) ->λs.(s s) (λx.x λy.y) ->λs.(s s) λy.y ->λy.y λy.y ->λy.y5 reductionsλf.λa.(f a) λx.x λy.y reduced onceLazyλs.(s s) (λf.λa.(f a) λx.x λy.y) 1=>(λf.λa.(f a) λx.x λy.y) 1(λf.λa.(f a) λx.x λy.y) 1=>(λa.(λx.x a) λy.y) 2(λa.(λx.x a) λy.y) 2=>(λx.x λy.y) 3(λx.x λy.y) 3=>λy.y λy.y =>

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

Saved successfully!

Ooh no, something went wrong!