Download presentation
Presentation is loading. Please wait.
Published byErik Walker Modified over 8 years ago
1
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우
2
2 Values and Reductions redex = reducible expression : -reduction
3
3 Call-by-name Call-by-value
4
4 Outline Abstract syntax of the -calculus V Operational semantics of the -calculus V Substitutions Programming in the -calculus
5
5 [e' / x] e Informally "substitute e' for every occurrence of x in e." Examples
6
6 Easy Cases First
7
7 Two Remaining Cases
8
8 First (stupid) attempt Second attempt But wait:
9
9 Names of bound variables do not matter. Hence –for a fresh variable y, Bound Variables
10
10 One Remaining Case
11
11 A Naive Attempt An anomaly: something for y
12
12 Free Variables Variables that are bound nowhere FV(e) = set of free variables in e
13
13 Free Variables Remain Free From the point of view of an outside observer, a free variable remains free until it is explicitly replaced. outside observer ? variable capture
14
14 Capture-Avoiding Substitution What happens if –the free variable y is captured and becomes a bound variable. –To an outside observer, it suddenly disappears!
15
15 Substitution Completed
16
16 We have to rename bound variables as necessary. Capture-Avoiding Substitution in Action
17
17 Conversion Renaming bound variables when necessary Okay because the names of bound variables do not matter. Examples
18
18 Formalization of -Conversion See the course notes! –It's more interesting than you might think.
19
19 Outline Abstract syntax of the -calculus V Operational semantics of the -calculus V Substitutions V Programming in the -calculus
20
20 A boolean value –"Give me two options and I will choose one for you!" Syntactic sugar Booleans
21
21 Examples Under the call-by-name strategy,
22
22 Logical Operators
23
23 Natural Numbers A natural number n –has the capability to repeat a given process n times. –"Give me a function f and I will return f n = f o f... f o f "
24
24 Church Numerals
25
25 Addition Key observation:
26
26 Multiplication Key observation: Alternatively
27
27 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 -calculus i.e., show that it is syntactic sugar.
28
28 Plan of attack 1.Assume a recursive function construct 2.Rewrite it as an expression in the -calculus i.e., show that it is syntactic sugar. Example: Factorial
29
29 fac to FAC
30
30 FAC produces a new function from f
31
31 Now we only need to find a fixed point of:
32
32 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)
33
33 Magic Revealed Fixed point combinator / Y combinator (call-by-value) fix F returns a fixed point of F.
34
34 Now we only need to find a fixed point of: Now we only need to compute:
35
35 Answer
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.