<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: An epiphany about Functional Programming and Lazy Evaluation</title>
	<atom:link href="http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/feed/" rel="self" type="application/rss+xml" />
	<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/</link>
	<description>Rambling about programming and life as a programmer - by Mathieu Martin</description>
	<pubDate>Fri, 21 Nov 2008 11:03:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: John Armstrong</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-11</link>
		<dc:creator>John Armstrong</dc:creator>
		<pubDate>Mon, 13 Aug 2007 16:01:08 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-11</guid>
		<description>There's also a certain sense in which lazy evaluation not only performs calculations "if and when they're needed", but that it does them "all at once".  When you dig into the semantics of functional programming, all you're doing is building one big function to calculate, rather than stringing together a bunch of little commands to do one after another.  This makes it (IMHO) a good candidate for a programming style suitable for quantum computation... once we actually have quantum computers.</description>
		<content:encoded><![CDATA[<p>There&#8217;s also a certain sense in which lazy evaluation not only performs calculations &#8220;if and when they&#8217;re needed&#8221;, but that it does them &#8220;all at once&#8221;.  When you dig into the semantics of functional programming, all you&#8217;re doing is building one big function to calculate, rather than stringing together a bunch of little commands to do one after another.  This makes it (IMHO) a good candidate for a programming style suitable for quantum computation&#8230; once we actually have quantum computers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: webmat</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-10</link>
		<dc:creator>webmat</dc:creator>
		<pubDate>Mon, 13 Aug 2007 11:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-10</guid>
		<description>For those who liked the article's comments, you can also look at &lt;a href="http://programming.reddit.com/info/2elwa/comments" rel="nofollow"&gt;the comments on reddit&lt;/a&gt;. There's interesting content there too.</description>
		<content:encoded><![CDATA[<p>For those who liked the article&#8217;s comments, you can also look at <a href="http://programming.reddit.com/info/2elwa/comments" rel="nofollow">the comments on reddit</a>. There&#8217;s interesting content there too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: webmat</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-9</link>
		<dc:creator>webmat</dc:creator>
		<pubDate>Mon, 13 Aug 2007 11:33:51 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-9</guid>
		<description>Thanks all for your comments. I am in fact probably mixing the concepts a bit, yes. Mea culpa :-)
After reading your comments, I realize I should probably have said that "functional programming language's non-strict semantics are to the detailed..." (thanks Cale). And yes, lazy evaluation is just one of the way to take advandage of the non-strict semantics.
Keep in mind one of the opening sentences of the article, however:
"Altough I haven’t had the chance yet to program with a functional programming language" ;-)</description>
		<content:encoded><![CDATA[<p>Thanks all for your comments. I am in fact probably mixing the concepts a bit, yes. Mea culpa :-)<br />
After reading your comments, I realize I should probably have said that &#8220;functional programming language&#8217;s non-strict semantics are to the detailed&#8230;&#8221; (thanks Cale). And yes, lazy evaluation is just one of the way to take advandage of the non-strict semantics.<br />
Keep in mind one of the opening sentences of the article, however:<br />
&#8220;Altough I haven’t had the chance yet to program with a functional programming language&#8221; ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: novhard</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-8</link>
		<dc:creator>novhard</dc:creator>
		<pubDate>Mon, 13 Aug 2007 11:12:53 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-8</guid>
		<description>i like about programming too ..
visit me at novhard.wordpress.com</description>
		<content:encoded><![CDATA[<p>i like about programming too ..<br />
visit me at novhard.wordpress.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurie Cheers</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-7</link>
		<dc:creator>Laurie Cheers</dc:creator>
		<pubDate>Mon, 13 Aug 2007 08:16:38 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-7</guid>
		<description>Lazy evaluation has everything to do with this. In a sequential program, you say "Do this, then this, then this". This is inherently a single-core process.

In a lazy evaluated program, you say "We need these pieces of information". You don't specify the order in which they get worked out, so the compiler is free to process them in any order, or split the calculations across many cores, .</description>
		<content:encoded><![CDATA[<p>Lazy evaluation has everything to do with this. In a sequential program, you say &#8220;Do this, then this, then this&#8221;. This is inherently a single-core process.</p>
<p>In a lazy evaluated program, you say &#8220;We need these pieces of information&#8221;. You don&#8217;t specify the order in which they get worked out, so the compiler is free to process them in any order, or split the calculations across many cores, .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DRMacIver</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-6</link>
		<dc:creator>DRMacIver</dc:creator>
		<pubDate>Mon, 13 Aug 2007 07:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-6</guid>
		<description>The implicit parallelism thing is mostly a myth. Especially in Haskell, the opportunities for it are few and far between, and the compiler doesn't really take advantage of them anyway.

Which isn't to say that I disagree with you (although I think we have a long way to go before the ability of the compiler to optimise pure lazy code is as good as the state of the art of garbage collection these days). It's just that the specific example is wrong.</description>
		<content:encoded><![CDATA[<p>The implicit parallelism thing is mostly a myth. Especially in Haskell, the opportunities for it are few and far between, and the compiler doesn&#8217;t really take advantage of them anyway.</p>
<p>Which isn&#8217;t to say that I disagree with you (although I think we have a long way to go before the ability of the compiler to optimise pure lazy code is as good as the state of the art of garbage collection these days). It&#8217;s just that the specific example is wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph Huang</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-5</link>
		<dc:creator>Joseph Huang</dc:creator>
		<pubDate>Mon, 13 Aug 2007 05:07:37 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-5</guid>
		<description>Shared thunks required by lazy evaluation make automatic parallelization harder. For a language already offering automatic parallelization, see

http://www.cs.mu.oz.au/research/mercury/information/papers.html#wangp-hons</description>
		<content:encoded><![CDATA[<p>Shared thunks required by lazy evaluation make automatic parallelization harder. For a language already offering automatic parallelization, see</p>
<p><a href="http://www.cs.mu.oz.au/research/mercury/information/papers.html#wangp-hons" rel="nofollow">http://www.cs.mu.oz.au/research/mercury/information/papers.html#wangp-hons</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-4</link>
		<dc:creator>Cale Gibbard</dc:creator>
		<pubDate>Mon, 13 Aug 2007 04:23:42 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-4</guid>
		<description>This is perhaps being overly picky, but what you are talking about is not so much lazy evaluation, but non-strict semantics. Non-strict semantics are what allow for a multitude of potential evaluation orders, and basically amount to saying that if there's a way for the evaluation to finish (under some order of reduction), then the result is what the result must be. It is possible to show that (in a pure language) any two evaluation orders which both produce a result must produce the same result.

Lazy evaluation implies a particular evaluation order (outermost-first, rather than strict-evaluation's innermost-first), along with the technique of sharing the computation of expressions which came from a function parameter being duplicated in the function's body. Lazy evaluation is an implementation of non-strict semantics -- it's possible to show that if some order of evaluation terminates and produces a result, then lazy evaluation will also terminate and produce the same thing.

However, that aside, even just lazy evaluation really does have a big impact on the way in which you can program. Because results are only produced if demanded, it becomes possible to define larger structures than you might need in your specific case (which is often easier than explicitly restricting your computation), and then have the remaining part of the computation only use what it needs. This allows you to decompose problems in new ways that you couldn't before, and get better code reuse.

Non-strict semantics, without the guarantee of lazy evaluation, allows compiler writers additional freedom to do things like parallelise (though this is really hard to accomplish automatically -- programmer annotations help a lot) or apply other evaluation strategies like strict evaluation automatically in places where it's verifiably safe to do so.</description>
		<content:encoded><![CDATA[<p>This is perhaps being overly picky, but what you are talking about is not so much lazy evaluation, but non-strict semantics. Non-strict semantics are what allow for a multitude of potential evaluation orders, and basically amount to saying that if there&#8217;s a way for the evaluation to finish (under some order of reduction), then the result is what the result must be. It is possible to show that (in a pure language) any two evaluation orders which both produce a result must produce the same result.</p>
<p>Lazy evaluation implies a particular evaluation order (outermost-first, rather than strict-evaluation&#8217;s innermost-first), along with the technique of sharing the computation of expressions which came from a function parameter being duplicated in the function&#8217;s body. Lazy evaluation is an implementation of non-strict semantics &#8212; it&#8217;s possible to show that if some order of evaluation terminates and produces a result, then lazy evaluation will also terminate and produce the same thing.</p>
<p>However, that aside, even just lazy evaluation really does have a big impact on the way in which you can program. Because results are only produced if demanded, it becomes possible to define larger structures than you might need in your specific case (which is often easier than explicitly restricting your computation), and then have the remaining part of the computation only use what it needs. This allows you to decompose problems in new ways that you couldn&#8217;t before, and get better code reuse.</p>
<p>Non-strict semantics, without the guarantee of lazy evaluation, allows compiler writers additional freedom to do things like parallelise (though this is really hard to accomplish automatically &#8212; programmer annotations help a lot) or apply other evaluation strategies like strict evaluation automatically in places where it&#8217;s verifiably safe to do so.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Warren W</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-3</link>
		<dc:creator>Warren W</dc:creator>
		<pubDate>Mon, 13 Aug 2007 03:36:59 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-3</guid>
		<description>As John Nowak says, you don't need Lazy Evaluation for the compiler to determine when instructions are independent and thus paralizable, this isn't really an advantage of Lazy evaluation.  Besides, parallelization at this level is too low level to be of much use, the overhead outweighs the benefit.

Also, I think you need to look in more detail about automatic memory manage. The speed increase they gained was probably due to a copy on garbage collect behavior. Whenever the garbage collector is run, it likely automatically restructures the allocated memory so that its contiguous.  Once this is the case, memory allocation just requires a few pointer arithmetic operations. In manual memory languages, since you cannot 'defrag' the active memory like this, you must maintain dirty/clean lists of memory, and every memory allocation is a search.

The speed increase for the memory managed version is amortized by the general slowdown of whatever garbage collection algorithm that is in use. Even still, automatic memory management is something I think nearly everyone should use and enjoy.

To round out this comment, one real benefit of lazy evaluation, is in the building of infinite streams. If you can describe a value as some formula of previous values, then it naturally fits into a list comprehension. For example, you could define fibiconni's numbers (0,1,1,2,3,5...) as a array and access any member of it (element 0 to element 6x10^66) -- the program will only compute as much as you actually use. This frees the programmer from some explicit bookkeeping.</description>
		<content:encoded><![CDATA[<p>As John Nowak says, you don&#8217;t need Lazy Evaluation for the compiler to determine when instructions are independent and thus paralizable, this isn&#8217;t really an advantage of Lazy evaluation.  Besides, parallelization at this level is too low level to be of much use, the overhead outweighs the benefit.</p>
<p>Also, I think you need to look in more detail about automatic memory manage. The speed increase they gained was probably due to a copy on garbage collect behavior. Whenever the garbage collector is run, it likely automatically restructures the allocated memory so that its contiguous.  Once this is the case, memory allocation just requires a few pointer arithmetic operations. In manual memory languages, since you cannot &#8216;defrag&#8217; the active memory like this, you must maintain dirty/clean lists of memory, and every memory allocation is a search.</p>
<p>The speed increase for the memory managed version is amortized by the general slowdown of whatever garbage collection algorithm that is in use. Even still, automatic memory management is something I think nearly everyone should use and enjoy.</p>
<p>To round out this comment, one real benefit of lazy evaluation, is in the building of infinite streams. If you can describe a value as some formula of previous values, then it naturally fits into a list comprehension. For example, you could define fibiconni&#8217;s numbers (0,1,1,2,3,5&#8230;) as a array and access any member of it (element 0 to element 6&#215;10^66) &#8212; the program will only compute as much as you actually use. This frees the programmer from some explicit bookkeeping.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Nowak</title>
		<link>http://programblings.com/2007/08/12/an-epiphany-about-functional-programming-and-lazy-evaluation/#comment-2</link>
		<dc:creator>John Nowak</dc:creator>
		<pubDate>Sun, 12 Aug 2007 23:47:45 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=12#comment-2</guid>
		<description>"Since the precise order of execution is not guaranteed, the bits of computing specified by the programmer in an FP can be optimized in other ways, too. For example, if the VM sees that a given instructions in the code is not dependent on the outcome of the previous instruction, it can execute them both simultaneously, if there are more than one cores available."

What does lazy evaluation have to do with this?</description>
		<content:encoded><![CDATA[<p>&#8220;Since the precise order of execution is not guaranteed, the bits of computing specified by the programmer in an FP can be optimized in other ways, too. For example, if the VM sees that a given instructions in the code is not dependent on the outcome of the previous instruction, it can execute them both simultaneously, if there are more than one cores available.&#8221;</p>
<p>What does lazy evaluation have to do with this?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
