cse-321 programming languages fixed point combinator

28
CSE-321 Programming Languages Fixed Point Combinator POSTECH March 29, 2006 박박박

Upload: thane-nash

Post on 03-Jan-2016

24 views

Category:

Documents


0 download

DESCRIPTION

CSE-321 Programming Languages Fixed Point Combinator. 박성우. POSTECH March 29, 2006. :  -reduction. redex = reducible expression. Values and Reductions. Substitution Completed. avoid variable captures. Outline. Abstract syntax of the  -calculus V - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE-321 Programming Languages Fixed Point Combinator

CSE-321 Programming Languages

Fixed Point Combinator

POSTECH

March 29, 2006

박성우

Page 2: CSE-321 Programming Languages Fixed Point Combinator

2

Values and Reductions

redex = reducible expression

: -reduction

Page 3: CSE-321 Programming Languages Fixed Point Combinator

3

Substitution Completed

avoid variable captures

Page 4: CSE-321 Programming Languages Fixed Point Combinator

4

Outline• Abstract syntax of the -calculus V• Operational semantics of the -calculus V• Substitutions V• Programming in the -calculus V• Fixed point combinator

– non-termination in the -calculus– recursive functions in the -calculus

Page 5: CSE-321 Programming Languages Fixed Point Combinator

5

Non-termination in -calculus

Page 6: CSE-321 Programming Languages Fixed Point Combinator

6

Recursive Functions in -calculus• Plan of attack

1. Assume a recursive function construct

fun f x. e

2. Rewrite it as an expression in the -calculusi.e., show that it is syntactic sugar.

Page 7: CSE-321 Programming Languages Fixed Point Combinator

7

• Plan of attack

1. Assume a recursive function construct

2. Rewrite it as an expression in the -calculusi.e., show that it is syntactic sugar.

Example: Factorial

Page 8: CSE-321 Programming Languages Fixed Point Combinator

8

fac to FAC

Page 9: CSE-321 Programming Languages Fixed Point Combinator

9

FAC produces a new function from f

Page 10: CSE-321 Programming Languages Fixed Point Combinator

10

KEY Observation on FAC

new!

Page 11: CSE-321 Programming Languages Fixed Point Combinator

11

FAC improves the input function f

:computes fac(0), fac(1), ..., fac(k)

:computes fac(0), fac(1), ..., fac(k), fac(k + 1)

Page 12: CSE-321 Programming Languages Fixed Point Combinator

12

Special Case

no matter what

Page 13: CSE-321 Programming Languages Fixed Point Combinator

13

Invariant:

Page 14: CSE-321 Programming Languages Fixed Point Combinator

14

FAC fac

Page 15: CSE-321 Programming Languages Fixed Point Combinator

15

Key Equation

Page 16: CSE-321 Programming Languages Fixed Point Combinator

16

What is f ?

Page 17: CSE-321 Programming Languages Fixed Point Combinator

17

Page 18: CSE-321 Programming Languages Fixed Point Combinator

18

(Earlier Slide)

Page 19: CSE-321 Programming Languages Fixed Point Combinator

19

Page 20: CSE-321 Programming Languages Fixed Point Combinator

20

Page 21: CSE-321 Programming Languages Fixed Point Combinator

21

Now we only need to solve:

Page 22: CSE-321 Programming Languages Fixed Point Combinator

22

Fixed Point• Fixed point of function f

V such that V = f (V)

• Ex.

f (x) = 2 - x

fixed point of f = 1

1 = f (1)

Page 23: CSE-321 Programming Languages Fixed Point Combinator

23

Now we only need to solve:

Now we only need to find a fixed point of:

Page 24: CSE-321 Programming Languages Fixed Point Combinator

24

Magic Revealed• Fixed point combinator / Y combinator

(call-by-value)

• fix F returns a fixed point of F.

Page 25: CSE-321 Programming Languages Fixed Point Combinator

25

Magic Explained

Page 26: CSE-321 Programming Languages Fixed Point Combinator

26

Now we only need to solve:

Now we only need to find a fixed point of:

Now we only need to compute:

Page 27: CSE-321 Programming Languages Fixed Point Combinator

27

Answer

Page 28: CSE-321 Programming Languages Fixed Point Combinator

28

If you are a masochist,• See the course notes to learn

how to derive the fixed point combinator!– There is a really crazy idea!