<?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: Folds for Imperative Programmers</title>
	<atom:link href="http://blog.tmorris.net/folds-for-imperative-programmers/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/folds-for-imperative-programmers/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Tue, 06 Jan 2009 05:48:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-658</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 09 Mar 2007 20:17:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-658</guid>
		<description>Hi sean, the premise of your statement is not correct. You say, "Now say we want to count the number of times it’s called.", but this is completely orthogonal to a software requirement, which is always based on a lambda abstraction. Rather than start talking about Church's theories, I will point out that the only reason you ever care about "the number of times it’s called", is because you're using C - not producing any useful lambda abstraction. In other words, there are lots of things you cannot do with Haskell (this is not one of them), but it is great that you can't because they have nothing to do with software (and usually, as in this case, everything to do with restrictions placed by the von Neumann machine (ick!)).

Furthermore, the ability to perform destructive update does not disqualify the ability to perform what you are asking using Haskell if indeed you correct it to be a sensible expression of software - that is, you pass the "number of times it’s called" as an additional argument/return value. This can be achieved cleanly by using the State monad.</description>
		<content:encoded><![CDATA[<p>Hi sean, the premise of your statement is not correct. You say, &#8220;Now say we want to count the number of times it’s called.&#8221;, but this is completely orthogonal to a software requirement, which is always based on a lambda abstraction. Rather than start talking about Church&#8217;s theories, I will point out that the only reason you ever care about &#8220;the number of times it’s called&#8221;, is because you&#8217;re using C - not producing any useful lambda abstraction. In other words, there are lots of things you cannot do with Haskell (this is not one of them), but it is great that you can&#8217;t because they have nothing to do with software (and usually, as in this case, everything to do with restrictions placed by the von Neumann machine (ick!)).</p>
<p>Furthermore, the ability to perform destructive update does not disqualify the ability to perform what you are asking using Haskell if indeed you correct it to be a sensible expression of software - that is, you pass the &#8220;number of times it’s called&#8221; as an additional argument/return value. This can be achieved cleanly by using the State monad.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sean</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-657</link>
		<dc:creator>sean</dc:creator>
		<pubDate>Thu, 08 Mar 2007 23:20:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-657</guid>
		<description>&lt;blockquote&gt;By the way, yes the Haskell equivalent is supposed to be 100 times shorter — that is the nature of a relatively expressive programming language.&lt;/blockquote&gt;
Nope.  That's the nature of implementing one language's idioms in another.  For an example going the other way, say we have a function
    char * echo(char * str) { return str; } // C
or
    pre = id -- haskell
and it's called all over our program.  Now say we want to count the number of times it's called.  In C, we just do this:

    int echo_count = 0;
    char * echo(char * str) { ++echo_count; return str; } // C

Global state is easy and idiomatic.  In Haskell, we're hosed -- "proper hosed".  Time to rewrite our whole program.</description>
		<content:encoded><![CDATA[<blockquote><p>By the way, yes the Haskell equivalent is supposed to be 100 times shorter — that is the nature of a relatively expressive programming language.</p></blockquote>
<p>Nope.  That&#8217;s the nature of implementing one language&#8217;s idioms in another.  For an example going the other way, say we have a function<br />
    char * echo(char * str) { return str; } // C<br />
or<br />
    pre = id &#8212; haskell<br />
and it&#8217;s called all over our program.  Now say we want to count the number of times it&#8217;s called.  In C, we just do this:</p>
<p>    int echo_count = 0;<br />
    char * echo(char * str) { ++echo_count; return str; } // C</p>
<p>Global state is easy and idiomatic.  In Haskell, we&#8217;re hosed &#8212; &#8220;proper hosed&#8221;.  Time to rewrite our whole program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-656</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 12 Jan 2007 20:58:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-656</guid>
		<description>Man, what a screw up!
I will bathe in the consolation that any future mistakes of such a trivial magnitude will be picked up immediately :)

Thanks to those who did and sorry to those who I have misled.</description>
		<content:encoded><![CDATA[<p>Man, what a screw up!<br />
I will bathe in the consolation that any future mistakes of such a trivial magnitude will be picked up immediately <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Thanks to those who did and sorry to those who I have misled.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nobody</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-655</link>
		<dc:creator>nobody</dc:creator>
		<pubDate>Mon, 08 Jan 2007 02:42:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-655</guid>
		<description>(Actually, the 'n' in 'fold c n xs' needs to commute with the elements of 'xs' too.)</description>
		<content:encoded><![CDATA[<p>(Actually, the &#8216;n&#8217; in &#8216;fold c n xs&#8217; needs to commute with the elements of &#8216;xs&#8217; too.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nobody</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-654</link>
		<dc:creator>nobody</dc:creator>
		<pubDate>Sat, 06 Jan 2007 16:19:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-654</guid>
		<description>Another mistake: associativity is

(a + b) + c = a + (b + c),

not

a + b = b + a,

which is commutativity. (But associativity is the property that makes the two forms equivalent if they both terminate.)</description>
		<content:encoded><![CDATA[<p>Another mistake: associativity is</p>
<p>(a + b) + c = a + (b + c),</p>
<p>not</p>
<p>a + b = b + a,</p>
<p>which is commutativity. (But associativity is the property that makes the two forms equivalent if they both terminate.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-653</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Fri, 05 Jan 2007 23:44:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-653</guid>
		<description>Ah, ok, I see now.  Thanks Tony and Jaak!</description>
		<content:encoded><![CDATA[<p>Ah, ok, I see now.  Thanks Tony and Jaak!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-652</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 05 Jan 2007 22:16:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-652</guid>
		<description>WOOPS!!

Sorry to anyone for whom I have caused confusion. It is me who was confused. My sincerest apologies. Ryan, I have updated in an attempt to correct your confusion for which I accept full responsibility.</description>
		<content:encoded><![CDATA[<p>WOOPS!!</p>
<p>Sorry to anyone for whom I have caused confusion. It is me who was confused. My sincerest apologies. Ryan, I have updated in an attempt to correct your confusion for which I accept full responsibility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaak</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-651</link>
		<dc:creator>Jaak</dc:creator>
		<pubDate>Fri, 05 Jan 2007 19:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-651</guid>
		<description>http://foldr.com/
http://foldl.com/

definitions of folds in haskell should be:

foldl _ e [] = e
foldl f e (x : xs) = foldl f (f e x) xs

and

foldr _ e [] = e
foldr f e (x : xs) = f x (foldr f e xs)

so "foldr (-) 97 i" is

(7 - (8 - (9 - (... (74 - 97))))


Yes. you got them backwards.</description>
		<content:encoded><![CDATA[<p><a href="http://foldr.com/" onclick="javascript:pageTracker._trackPageview('/outbound/comment/foldr.com');" rel="nofollow">http://foldr.com/</a><br />
<a href="http://foldl.com/" onclick="javascript:pageTracker._trackPageview('/outbound/comment/foldl.com');" rel="nofollow">http://foldl.com/</a></p>
<p>definitions of folds in haskell should be:</p>
<p>foldl _ e [] = e<br />
foldl f e (x : xs) = foldl f (f e x) xs</p>
<p>and</p>
<p>foldr _ e [] = e<br />
foldr f e (x : xs) = f x (foldr f e xs)</p>
<p>so &#8220;foldr (-) 97 i&#8221; is</p>
<p>(7 - (8 - (9 - (&#8230; (74 - 97))))</p>
<p>Yes. you got them backwards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-650</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Fri, 05 Jan 2007 18:50:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-650</guid>
		<description>I'm pretty sure I get the concept, but I don't see why foldr (-) 97 i evaluates to 41.  When I do it by hand (97 - 74 - 64 ...), I'm getting -321.  Am I seriously confused, or is it just a typo?</description>
		<content:encoded><![CDATA[<p>I&#8217;m pretty sure I get the concept, but I don&#8217;t see why foldr (-) 97 i evaluates to 41.  When I do it by hand (97 - 74 - 64 &#8230;), I&#8217;m getting -321.  Am I seriously confused, or is it just a typo?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://blog.tmorris.net/folds-for-imperative-programmers/#comment-649</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Fri, 05 Jan 2007 16:10:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/folds-for-imperative-programmers/#comment-649</guid>
		<description>You've got it backwards.  A "fold left" starts on the left and ends on the right.  A "fold right" starts on the right and ends on the left.

The difference matters especially with structures like functional cons lists.  A fold left can be written tail-recursively; a fold right cannot (except by reversing the list and folding left).</description>
		<content:encoded><![CDATA[<p>You&#8217;ve got it backwards.  A &#8220;fold left&#8221; starts on the left and ends on the right.  A &#8220;fold right&#8221; starts on the right and ends on the left.</p>
<p>The difference matters especially with structures like functional cons lists.  A fold left can be written tail-recursively; a fold right cannot (except by reversing the list and folding left).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
