Aaron Watters writes:
Frankly, I think I thought I understood this once but now I know I don't.
8^) That's what I said when I backed into the idea via medusa a couple of years ago.
How're continuations more powerful than coroutines? And why can't they be implemented using threads (and semaphores etc)?
My understanding of the original 'coroutine' (from Pascal?) was that it allows two procedures to 'resume' each other. The classic coroutine example is the 'samefringe' problem: given two trees of differing structure, are they equal in the sense that a traversal of the leaves results in the same list? Coroutines let you do this efficiently, comparing leaf-by-leaf without storing the whole tree.
continuations can do coroutines, but can also be used to implement backtracking, exceptions, threads... probably other stuff I've never heard of or needed.
The reason that Scheme and ML are such big fans of continuations is because they can be used to implement all these other features. Look at how much try/except and threads complicate other language implementations. It's like a super-tool-widget - if you make sure it's in your toolbox, you can use it to build your circular saw and lathe from scratch.
Unfortunately there aren't many good sites on the web with good explanatory material. The best reference I have is "Essentials of Programming Languages". For those that want to play with some of these ideas using little VM's written in Python: