<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dysfunctional Programming &#187; functional programming</title>
	<atom:link href="http://ra3s.com/wordpress/dysfunctional-programming/category/functional-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://ra3s.com/wordpress/dysfunctional-programming</link>
	<description>(λ (a b) a) vs (λ (a b) b)</description>
	<lastBuildDate>Wed, 25 Jan 2012 17:05:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>FAIC: CPS Revisited</title>
		<link>http://ra3s.com/wordpress/dysfunctional-programming/faic-cps-revisited/</link>
		<comments>http://ra3s.com/wordpress/dysfunctional-programming/faic-cps-revisited/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 21:46:38 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[functional programming]]></category>
		<category><![CDATA[repost]]></category>

		<guid isPermaLink="false">http://ra3s.com/wordpress/dysfunctional-programming/?p=258</guid>
		<description><![CDATA[Eric Lippert of Fabulous Adventures In Coding has posted a series on CPS tranformation and different control flow abstractions. Good stuff &#8212; recommended reading for translating the crazy stuff I talk about into &#8216;normal&#8217; code. Continuation Passing Style Revisited, Part &#8230; <a href="http://ra3s.com/wordpress/dysfunctional-programming/faic-cps-revisited/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Eric Lippert of Fabulous Adventures In Coding has posted a series on CPS tranformation and different control flow abstractions. Good stuff &#8212; recommended reading for translating the crazy stuff I talk about into &#8216;normal&#8217; code.</p>
<ul>
<li><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/21/continuation-passing-style-revisited-part-one.aspx">Continuation Passing Style Revisited, Part One</a>.</li>
<li><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/22/continuation-passing-style-revisited-part-two-handwaving-about-control-flow.aspx">Continuation  Passing Style Revisited Part Two: Handwaving about control flow</a>.</li>
<li><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/25/continuation-passing-style-revisited-part-three-musings-about-coroutines.aspx">Continuation Passing Style Revisited Part Three: Musings about coroutines</a>.</li>
<li><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/26/continuation-passing-style-revisited-part-four-turning-yourself-inside-out.aspx">Continuation Passing Style Revisited Part Four: Turning yourself inside out</a>.</li>
<li><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/27/continuation-passing-style-revisited-part-five-cps-and-asynchrony.aspx">Continuation Passing Style Revisited Part Five: CPS and Asynchrony</a>.</li>
</ul>
<p><span id="more-258"></span><span style="text-decoration: line-through;">I bet part 2 will cover exception handling. That, or call/cc, then EH in part 3. We&#8217;ll see <img src='http://ra3s.com/wordpress/dysfunctional-programming/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </span></p>
<p>Update (10/22): Yay, I was right, EH is up next.  He also writes &#8220;<strong>Next time:</strong> handwaving about coroutines&#8221;.  I&#8217;m sure call/cc will be in part 3.</p>
<p>Update (10/25): Part 3 is up &#8212; skips call/cc (makes sense, as Eric it talking about writing CPS explicitly) moving straight to one application of CPS: coroutines. Ominiously ends with &#8220;<strong>Next time</strong>: if Continuation Passing Style is so awesome then why don’t we all use this technique every day?&#8221; Presumably he will be talking about the specific implementation technique he&#8217;s chosen, as various runtime environments (usually Scheme implementations) *do* use CPS for compilation all the time, and a few do so with no ill effect.</p>
<p>Update (10/27): Part 4 and 5 are up.  Part 4 notes that CPS is generally *hard* to understand for most folks, but that CPS is ultimately general purpose, making for quick implementation of a wide variety of programming language control flow constructs.</p>
<p>Part 5 further talks about the explicit use of CPS in designing asynchronous programming APIs. I&#8217;m somewhat disappointed that Eric skips over the CPS to model for loops, instead resorting to a state machine like the C# compiler uses when compiling iterator syntax. It&#8217;s a fine implementation technique, but it seems like a missed opportunity to me, and it would have avoided the &#8220;definite assignment problem&#8221; he mentioned. And lastly, while the invocation of the continuation was straightforward in CPS, a lot of synchronization work has been glossed over in &#8216;SetContinuation&#8217; &#8212; the continuation may not always be ready by the time that &#8216;AsyncFetch&#8217; goes to invoke it. This seems unnecessarily wasteful, as the caller always knows the continuation they&#8217;re about to set &#8212; the caller code is simplified only by reordering, at the expense of runtime cost and added complexity in AsyncFetch.</p>
<p>I think the switch to use &#8216;SetContinuation/GetResults&#8217; is done too early. It makes it easier to connect his example to .Net&#8217;s <a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx">Task Parallel Library</a>, but now there isn&#8217;t a single example in direct CPS style that demonstrates asynchrony.</p>
<p>I&#8217;m only so critical of Part 5 as I think Eric Lippert has done quite well in the rest of this series. To be balanced, many programmers will find the state machine model easier to read. As a CPS topic, I find Part 5 lacking; It shines as an explaination of asynchrony in .Net.  It a very good piece, but is an ugly duckling in a CPS series.</p>
<p>Again, I appreciate his work here.  Please take the time to give this series a read.</p>
<p><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/22/continuation-passing-style-revisited-part-two-handwaving-about-control-flow.aspx"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ra3s.com/wordpress/dysfunctional-programming/faic-cps-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GOTOs inconvenient</title>
		<link>http://ra3s.com/wordpress/dysfunctional-programming/gotos-inconvenient/</link>
		<comments>http://ra3s.com/wordpress/dysfunctional-programming/gotos-inconvenient/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:03:12 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[functional programming]]></category>
		<category><![CDATA[repost]]></category>

		<guid isPermaLink="false">http://ra3s.com/wordpress/dysfunctional-programming/?p=200</guid>
		<description><![CDATA[From &#8220;The Discovery of Continuations&#8221; The talk actually had one direct and important consequence for computing. Under the inspiration of the notion of the unnecessity of goto’s, Dijkstra spent that evening constructing realistic examples of programs without goto’s, … So &#8230; <a href="http://ra3s.com/wordpress/dysfunctional-programming/gotos-inconvenient/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>From &#8220;<a href="http://www.brics.dk/~hosc/vol06/contents.html">The Discovery of Continuations</a>&#8221;</p>
<blockquote><p>The talk actually had one direct and important consequence for computing. Under the inspiration of the notion of the unnecessity of goto’s, Dijkstra spent that evening constructing realistic examples of programs without goto’s, … So while van Wijngaarden said that goto’s were unnecessary … , Dijkstra stretched the point to say that goto’s were inconvenient. The latter lesson stuck. &#8212; McIlroy</p></blockquote>
<p>The <a href="http://en.wikipedia.org/wiki/Continuation-passing_style">continuation passing transformation </a>grew out an attempt to formalize <a href="http://en.wikipedia.org/wiki/Goto_statement">GOTO</a>, and ended up both obsoleting it as well as producing new, better structured control primitives (for example, <a href="http://en.wikipedia.org/wiki/Break_statement#Early_exit_from_loops">break</a>).  It&#8217;s strange to me that I could have gone as far as I have, as a programmer, without having a good understanding of this concept. We use it implicitly all the time &#8212; the <a href="http://en.wikipedia.org/wiki/Call_stack">call stack </a>of course &#8212; but rarely consider all of the ramifications (threading) and certainly not all of the utility (coroutines, exception handling, etc).</p>
]]></content:encoded>
			<wfw:commentRss>http://ra3s.com/wordpress/dysfunctional-programming/gotos-inconvenient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loop variable closure semantics</title>
		<link>http://ra3s.com/wordpress/dysfunctional-programming/loop-variable-closure-semantics/</link>
		<comments>http://ra3s.com/wordpress/dysfunctional-programming/loop-variable-closure-semantics/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 04:07:30 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Csharp]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://ra3s.com/wordpress/dysfunctional-programming/?p=76</guid>
		<description><![CDATA[Just a quick post, haven&#8217;t shared anything in a while, but found this discussion on loop variables and closures interesting &#8212; well, inflammatory, actually. Erik Lippert writes (and again) on C# loop variable closure semantics. The confusion arises because a &#8230; <a href="http://ra3s.com/wordpress/dysfunctional-programming/loop-variable-closure-semantics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a quick post, haven&#8217;t shared anything in a while, but found this discussion on loop variables and closures interesting &#8212; well, inflammatory, actually.</p>
<p><span id="more-76"></span><a href="http://blogs.msdn.com/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx">Erik Lippert writes</a> (<a href="http://blogs.msdn.com/ericlippert/archive/2009/11/16/closing-over-the-loop-variable-part-two.aspx">and again</a>) on C# loop variable closure semantics.  The confusion arises because a &#8220;foreach&#8221; loop&#8217;s iteration variable is not assignable in C# &#8212; which leads the programmer to think it is constant &#8212; but actually it is variable, getting re-bound each iteration to the next item in the sequence.  This normally wouldn&#8217;t matter much, but if you have a lambda that closes over that loop variable, the lambda will observe the re-bindings each iteration.</p>
<p>While searching for Haskell blogs, found <a href="http://notes-on-haskell.blogspot.com/2008/09/closures-and-scoping-rules.html">this interesting response </a>by one Adam Turoff.  He mentions Ruby, JavaScript, and Scheme, but especially Haskell.  He points out quite rightly that, in pure functional code, capturing a reference or copy is indistinguishable due to referential equality.  C# was very close to getting this right &#8212; it prevents the user from rebinding the variable, but the real error was forgetting to prevent itself from doing the same.</p>
<p>However, the compiler isn&#8217;t really implementing a loop variable, it&#8217;s actually thin syntax over the .Current property of the iterator.  The &#8216;foreach&#8217; loop aims only to expose the CLR iterator pattern, so it makes sense that it would remain as close to it as possible.  Another possible explanation: the real error was allowing the programmer to close over a variable that wasn&#8217;t really a variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://ra3s.com/wordpress/dysfunctional-programming/loop-variable-closure-semantics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

