document updated 15 years ago, on Apr 10, 2009
What's the difference between generators, coroutines, and continuations?
- generators
- they can only return multiple times (like a read-only pipe) — they can't be called multiple times (like a writable pipe)
- coroutines
- they're like a pipe that can be written to, as well as read from
- they're equivalent to fibers (as long as the language allows fine-grained control of fibers)
- the word "coroutine" can encompass widely varying functionality -- see chapter2 here for a classification of them
- 2.1. asymmetric vs symmetric
- asymmetric — subordinate and caller
- symmetric — operate at the same hierarchical level
- 2.2 first-class vs constrained
- first-class —
- constrained — can only be used for iterators/generators
- 2.3 stackful vs not stackful
- stackful — it can yield from lower levels (e.g. inside for-loops, etc)
- not stackful — it can only resume from the top-level that it was started from
- 2.4 full coroutines — both 1) first-class, and 2) stackful
- continuations
- they're the ultimate in execution-flow-control
- explanations that make the most sense to me:
[1]
[2]
[3]