<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx</link><description>There are some technical words that cause quite a stir even amongst geeks.&amp;#160; When someone says the word &amp;quot;continuation&amp;quot; , people's eyes glaze over and they seek the first opportunity to change the subject.&amp;#160; The stir is caused because</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#8850346</link><pubDate>Tue, 12 Aug 2008 12:16:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8850346</guid><dc:creator>Tobias</dc:creator><description>&lt;p&gt;God I love this sentence (I had to read it at least five times :)&lt;/p&gt;
&lt;p&gt;&amp;quot;The continuation of the computation at the invocation of F is the remainder of the program execution beginning with incrementing x in the method M.&amp;quot;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8850346" width="1" height="1"&gt;</description></item><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#7384552</link><pubDate>Sat, 02 Feb 2008 10:51:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7384552</guid><dc:creator>Jigang Sun</dc:creator><description>&lt;p&gt;To explain a complex concept in a simple and &amp;nbsp;very understandable way is a contribution. I really do not understand why other mathematicians explain the simple word in a complicated way. If this page were available earlier, my thesis could have been finished better. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7384552" width="1" height="1"&gt;</description></item><item><title>Continuation</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#7185375</link><pubDate>Mon, 21 Jan 2008 18:58:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7185375</guid><dc:creator>Greg</dc:creator><description>&lt;p&gt;We've been using this for more than 20 years to fake mutithreading on single CPU embedded machine in C. &amp;nbsp;these environments typically do not have threading and usually have almost no Operating System.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7185375" width="1" height="1"&gt;</description></item><item><title>The Marvels of Monads</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#7064393</link><pubDate>Fri, 11 Jan 2008 03:06:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7064393</guid><dc:creator>Yet Another Language Geek</dc:creator><description>&lt;p&gt;If the word &amp;amp;quot;continuation&amp;amp;quot; causes eyes to glaze over, then the word &amp;amp;quot;monad&amp;amp;quot; induces&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7064393" width="1" height="1"&gt;</description></item><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#7010862</link><pubDate>Mon, 07 Jan 2008 03:23:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7010862</guid><dc:creator>Sadek Drobi</dc:creator><description>&lt;p&gt;Great post Wes! Do you mean by &amp;quot;M&amp;quot; the monadic one? Anyway, I hope to see some useful monads in C#, and maybe some syntax help for it from the language who knows...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7010862" width="1" height="1"&gt;</description></item><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#6842110</link><pubDate>Sun, 23 Dec 2007 08:56:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6842110</guid><dc:creator>wesdyer</dc:creator><description>&lt;p&gt;Derek &amp;amp; Peter:&lt;/p&gt;
&lt;p&gt;Fantastic comments.&lt;/p&gt;
&lt;p&gt;We use CPS to implement cooperative threading in JavaScript in Volta.&lt;/p&gt;
&lt;p&gt;It is definitely true that a full CPS transform isn't very helpful in C# (to humans), but there are still many areas where it helps to convert portions of code to CPS.&lt;/p&gt;
&lt;p&gt;As you have probably guessed, my next post will start to show another way (without CallCC) to take advantage of CPS without turning code inside-out.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6842110" width="1" height="1"&gt;</description></item><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#6841990</link><pubDate>Sun, 23 Dec 2007 08:41:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6841990</guid><dc:creator>Derek Elkins</dc:creator><description>&lt;p&gt;As a quick note adding to Peter Thatcher's comment: Indeed, continuations and/or continuation passing style (CPS) can be used to implement concurrency (i.e. implement very lightweight threads) with user-definable schedulers. &amp;nbsp;By itself, it would be cooperative concurrency.&lt;/p&gt;
&lt;p&gt;I'd like to expand the UI comment as well. &amp;nbsp;As you say, the CPS transformation systematically takes &amp;quot;normal&amp;quot; code (called direct style) and turns it &amp;quot;inside-out.&amp;quot; &amp;nbsp;Why do you want your code inside-out? &amp;nbsp;You don't. &amp;nbsp;Unfortunately, some interfaces, specifically event-based ones, require it, e.g. many GUI frameworks and web applications. &amp;nbsp;If the language has support for CallCC, you can write the direct style code and have it transparently work with an event-based GUI framework. &amp;nbsp;When you first started programming, you might have written a program that reads two numbers from the console and displays the sum. &amp;nbsp;With continuations, you could write code of that simplicity and have it work for GUIs or web applications (in fact, you could make it so that the exact same code will do all three depending on how you instantiate it.)&lt;/p&gt;
&lt;p&gt;Continuation passing style is one way to support CallCC if your language doesn't, but unfortunately, continuation passing style is of very limited utility in C#. &amp;nbsp;CPS transforming your code causes all functions in it to never return. &amp;nbsp;Since, you can't rely on tail call optimization, this means that the stack will just build and build until it overflows. &amp;nbsp;You can avoid this to some degree, but only by avoiding many of the sort of things that make CPS and continuations interesting. &amp;nbsp;One of the things you can still do is the &amp;quot;uninversion&amp;quot; of control described above with regards to event-based systems. (You end up inadvertently implementing tail calls through trampolining.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6841990" width="1" height="1"&gt;</description></item><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#6838810</link><pubDate>Sun, 23 Dec 2007 01:09:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6838810</guid><dc:creator>Peter Thatcher</dc:creator><description>&lt;p&gt;I'd like to add that CPS can also be used to simulate message-passing systems like Erlang or Scala have in a language without threads, including Javascript. &amp;nbsp;In that case, you do something like the following Python:&lt;/p&gt;
&lt;p&gt;receive(lambda msg : print msg)&lt;/p&gt;
&lt;p&gt;Of course, that only receives one message. To loop, you need to either call more receives in the passed cotinuation or play trickery with specific language features like generators.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6838810" width="1" height="1"&gt;</description></item><item><title>re: Continuation-Passing Style</title><link>http://blogs.msdn.com/b/wesdyer/archive/2007/12/22/continuation-passing-style.aspx#6835445</link><pubDate>Sat, 22 Dec 2007 15:57:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6835445</guid><dc:creator>Tanveer Badar</dc:creator><description>&lt;p&gt;Excellent post. Really enjoyed it. And my head didn't explode :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6835445" width="1" height="1"&gt;</description></item></channel></rss>