<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Learning Haskell and Number Theory: The End of GCD</title>
	<atom:link href="http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/</link>
	<description>software, programming languages, and other ideas</description>
	<lastBuildDate>Fri, 13 Nov 2009 13:07:15 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Don Stewart</title>
		<link>http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-103</link>
		<dc:creator>Don Stewart</dc:creator>
		<pubDate>Sat, 07 Jul 2007 04:56:50 +0000</pubDate>
		<guid isPermaLink="false">http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-103</guid>
		<description>See &lt;a href=&quot;http://haskell.org/haskellwiki/GCD_inlining_strictness_and_CSE&quot; rel=&quot;nofollow&quot;&gt;http://haskell.org/haskellwiki/GCD_inlining_strictness_and_CSE&lt;/a&gt; for an analysis of how CSE, strictness, inlining and specialisation interact to get the best code from this example. :-)</description>
		<content:encoded><![CDATA[<p>See <a href="http://haskell.org/haskellwiki/GCD_inlining_strictness_and_CSE" rel="nofollow">http://haskell.org/haskellwiki/GCD_inlining_strictness_and_CSE</a> for an analysis of how CSE, strictness, inlining and specialisation interact to get the best code from this example. :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-101</link>
		<dc:creator>Cale Gibbard</dc:creator>
		<pubDate>Sat, 07 Jul 2007 04:30:03 +0000</pubDate>
		<guid isPermaLink="false">http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-101</guid>
		<description>While your solution with &quot;(gcd1 p x) `seq` gcdmany&#039; (gcd1 p x) xs&quot; will work to stop the stack overflow, it will also cause GHC to evaluate gcd1 twice as many times. GHC is *not* going to do CSE here -- it only does a particularly trivial form of CSE that this isn&#039;t covered by. The reason that it causes the stack not to overflow is that evaluating that gcd1 will inadvertently force the evaluation of p (supposing that your number type is strict), like the bang patterns do, but at a far greater expense.

You&#039;ll effectively cut the number of times gcd1 runs in half by forcing it to share, using the &quot;let g = gcd1 p x in g `seq` gcdmany&#039; g xs&quot; variant.

To see this, try profiling the code and looking at what happens to the &quot;entries&quot; column when you make the change.</description>
		<content:encoded><![CDATA[<p>While your solution with &#8220;(gcd1 p x) `seq` gcdmany&#8217; (gcd1 p x) xs&#8221; will work to stop the stack overflow, it will also cause GHC to evaluate gcd1 twice as many times. GHC is *not* going to do CSE here &#8212; it only does a particularly trivial form of CSE that this isn&#8217;t covered by. The reason that it causes the stack not to overflow is that evaluating that gcd1 will inadvertently force the evaluation of p (supposing that your number type is strict), like the bang patterns do, but at a far greater expense.</p>
<p>You&#8217;ll effectively cut the number of times gcd1 runs in half by forcing it to share, using the &#8220;let g = gcd1 p x in g `seq` gcdmany&#8217; g xs&#8221; variant.</p>
<p>To see this, try profiling the code and looking at what happens to the &#8220;entries&#8221; column when you make the change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cdsmith</title>
		<link>http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-99</link>
		<dc:creator>cdsmith</dc:creator>
		<pubDate>Fri, 06 Jul 2007 18:59:32 +0000</pubDate>
		<guid isPermaLink="false">http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-99</guid>
		<description>Paul, at least with GHC 6.6 and GHC 6.7 latest development version, the seq works as shown in the article.  At least on [1 .. 1000000], gcdmany fails with a stack overflow without the seq, and succeeds with it.  I&#039;d be interested if you have a source for the need to use a let binding, but it doesn&#039;t match what I see.</description>
		<content:encoded><![CDATA[<p>Paul, at least with GHC 6.6 and GHC 6.7 latest development version, the seq works as shown in the article.  At least on [1 .. 1000000], gcdmany fails with a stack overflow without the seq, and succeeds with it.  I&#8217;d be interested if you have a source for the need to use a let binding, but it doesn&#8217;t match what I see.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sorear</title>
		<link>http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-98</link>
		<dc:creator>sorear</dc:creator>
		<pubDate>Fri, 06 Jul 2007 16:07:05 +0000</pubDate>
		<guid isPermaLink="false">http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-98</guid>
		<description>There is a third possibility: Adding seqs can make your program vastly slower and use vastly more memory.  After all - laziness is usually a good thing!

rot13 ch
  &#124; ch &gt;= &#039;a&#039; &amp;&amp; ch = &#039;n&#039; &amp;&amp; ch = &#039;A&#039; &amp;&amp; ch = &#039;N&#039; &amp;&amp; ch </description>
		<content:encoded><![CDATA[<p>There is a third possibility: Adding seqs can make your program vastly slower and use vastly more memory.  After all &#8211; laziness is usually a good thing!</p>
<p>rot13 ch<br />
  | ch &gt;= &#8216;a&#8217; &amp;&amp; ch = &#8216;n&#8217; &amp;&amp; ch = &#8216;A&#8217; &amp;&amp; ch = &#8216;N&#8217; &amp;&amp; ch</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Johnson</title>
		<link>http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-94</link>
		<dc:creator>Paul Johnson</dc:creator>
		<pubDate>Fri, 06 Jul 2007 08:19:37 +0000</pubDate>
		<guid isPermaLink="false">http://cdsmith.wordpress.com/2007/07/05/learning-haskell-and-number-theory-the-end-of-gcd/#comment-94</guid>
		<description>(gcd1 p x) `seq` gcdmany’ (gcd1 p x) xs

As I understand it GHC doesn&#039;t do common subexpression elimination.  So surely this will compute (gcd1 p x) eagerly, then throw away the result and do it again lazily.

What you would need to do is more like:

   let g = gcd1 p x in g `seq` gcdmany’ g xs

But I may have misunderstood.

Paul</description>
		<content:encoded><![CDATA[<p>(gcd1 p x) `seq` gcdmany’ (gcd1 p x) xs</p>
<p>As I understand it GHC doesn&#8217;t do common subexpression elimination.  So surely this will compute (gcd1 p x) eagerly, then throw away the result and do it again lazily.</p>
<p>What you would need to do is more like:</p>
<p>   let g = gcd1 p x in g `seq` gcdmany’ g xs</p>
<p>But I may have misunderstood.</p>
<p>Paul</p>
]]></content:encoded>
	</item>
</channel>
</rss>
