Download presentation
Presentation is loading. Please wait.
Published byEdith Moore Modified over 9 years ago
1
CSE-321 Programming Languages -Calculus (II) POSTECH March 27, 2006 박성우
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 Because, 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 Those variables that are bound nowhere FV(e) = set of free variables in e
13
13 Free Variables vs. Bound Variables An outside observer does care about free variables. An outside observer does not care about bound variables. From the point of view of an outside observer:
14
14 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
15
15 Capture-Avoiding Substitution What happens if –the free variable y is captured and becomes a bound variable. –To an outside observer, it suddenly disappears!
16
16 Substitution Completed
17
17 We have to rename bound variables as necessary. Capture-Avoiding Substitution in Action
18
18 Conversion Renaming bound variables when necessary Okay because the names of bound variables do not matter. Examples
19
19 Formalization of -Conversion See the course notes! –It's more interesting than you might think.
20
20 Outline Abstract syntax of the -calculus V Operational semantics of the -calculus V Substitutions V Programming in the -calculus –A LOT OF FUN!
21
21 A boolean value –"Give me two options and I will choose one for you!" Syntactic sugar Booleans
22
22 Examples Under the call-by-name strategy,
23
23 Logical Operators
24
24 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 "
25
25 Church Numerals
26
26 Addition Key observation:
27
27 Multiplication Key observation: Alternatively
28
28 Others Pairs Natural numbers –predecessor: DIFFICULT –subtraction –exponentiation –... Lists See Course Notes and Pierce Chapter 5 for more examples.
29
29 Next Lecture Recursion in the -calculus –Read Course Notes!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.