Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Scala "continuations" just a funky syntax for defining and using Callback Functions?

And I mean that in the same sense that a C/Java for is just a funky syntax for a while loop.

I still remember when first learning about the for loop in C, the mental effort that had to go into understanding the execution sequence of the three control expressions relative to the loop statement. Seems to me the same sort of effort has to be applied to understand Continuations (in Scala and I guess probably other languages).

And then there's the obvious follow-up question... if so, then what's the point? It seems like a lot of pain (language complexity, programmer errors, unreadable programs, etc) for no gain.

like image 389
Alex R Avatar asked Apr 23 '10 18:04

Alex R


1 Answers

In some sense, yes, continuations are funky syntax for using callbacks. You can manually perform a very complex global transformation on your code (the so called continuation-passing-style transformation), and you will get continuations on your hands without direct language support.

However, transforming your entire codebase is probably not very practical, and the resulting code is hard to read, so having the compiler do it for you behind the scenes is MUCH better.

like image 101
hzap Avatar answered Oct 13 '22 05:10

hzap