CSE-321 Programming Languages -Calculus (II) POSTECH March 27, 2006 박성우.
CSE-321 Programming Languages Fixed Point Combinator
-
Upload
thane-nash -
Category
Documents
-
view
24 -
download
0
description
Transcript of CSE-321 Programming Languages Fixed Point Combinator
CSE-321 Programming Languages
Fixed Point Combinator
POSTECH
March 29, 2006
박성우
2
Values and Reductions
redex = reducible expression
: -reduction
3
Substitution Completed
avoid variable captures
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
5
Non-termination in -calculus
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.
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
8
fac to FAC
9
FAC produces a new function from f
10
KEY Observation on FAC
new!
11
FAC improves the input function f
:computes fac(0), fac(1), ..., fac(k)
:computes fac(0), fac(1), ..., fac(k), fac(k + 1)
12
Special Case
no matter what
13
Invariant:
14
FAC fac
15
Key Equation
16
What is f ?
17
18
(Earlier Slide)
19
20
21
Now we only need to solve:
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)
23
Now we only need to solve:
Now we only need to find a fixed point of:
24
Magic Revealed• Fixed point combinator / Y combinator
(call-by-value)
• fix F returns a fixed point of F.
25
Magic Explained
26
Now we only need to solve:
Now we only need to find a fixed point of:
Now we only need to compute:
27
Answer
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!