V Continuations - Programming Language Laboratory @ POSTECH

CSE-321 Programming Languages
Continuation
a.k.a GOTO of SML
박성우
POSTECH
April 19, 2006
Multiplying a List of Integers
2
An Improvement
3
Non-local Jump
4
Outline
• Motivating example V
• Evaluation contexts
• Continuations
5
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"
6
Typing Evaluation Contexts
7
What are Continuations?
•

– Give me an expression of type A.
– Then I will return an expression of type C.
 is a continuation!
8
Where is a continuation?
9
Outline
• Motivating example V
• Evaluation contexts V
• Continuations
10
Simply Typed -Calculus
11
Reduction Rules
12
First-class Continuations
13
Exercises
14
Makes Sense?
15
Typing Continuations
16
17
18
How do we return x?
How can we pass x to the outside of throw?
19
Answer: Throw!
20
Outline
•
•
•
•
Motivating example V
Evaluation contexts V
Continuations V
Something important
21
Midterm
• Read the Course Notes.
– up to the chapters that I finish writing by Friday.
– check the discussion board.
• Review Assignments.
– Some questions will be based on Assignments.
• Read the handout for Assignment 5.
22