CSE-321 Programming Languages
Continuation
박성우
POSTECH
May 9, 2007
Commonalities?
goto
• Too powerful
• Too dangerous
2
"Precious~"
• Too powerful
– turns you invisible!
– gives you an unusually long and active life!
• Too dangerous
– turns you into an evil creature!
– will eventually enslave you!
3
goto
• Too powerful
– can simulate all control constructs
• for, while, repeat/until
• switch
• Too dangerous
– damages code readability
4
Continuation = goto of SML
• Too powerful
– code optimization
– simple, elegant implementation of concurrency
– compilation technique
• CPS transformation used in SML/NJ
• Too dangerous
– damages code readability
5
Outline
• Introduction V
• Motivating example
• Evaluation contexts
• Continuations
6
Multiplying a List of Integers
7
An Improvement
8
Non-local Jump
9
Outline
• Introduction V
• Motivating example V
• Evaluation contexts
• Continuations
10
Evaluation Contexts
• An evaluation context:
– an expression with a hole
– "Give me an expression of type A"
– "Then I will return an expression of type B"
11
Typing Evaluation Contexts
12
What are Continuations?
•
– Give me an expression of type A.
– Then I will return an expression of type C.
is a continuation!
13
Where is a continuation?
14
Outline
• Introduction V
• Motivating example V
• Evaluation contexts V
• Continuations
15
Simply Typed -Calculus
16
Reduction Rules
17
First-class Continuations
18
Exercises
19
Makes Sense?
20
Typing Continuations
21
22
See the Course Notes
for an answer.
Big Announcement!
Special Assignment
• Credit
– unknown
• Deadline: midnight May 29 (Tuesday)
– no extension
• Where
– handin directory cs321/handin/hw_photo/
• What:
– JPEG picture of YOU with a big smile ;-)
– size: 200 by 260
– name: me.jpg
• case-sensitive
28