<?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/"
		>
<channel>
	<title>Comments on: GHC sometimes loops</title>
	<atom:link href="http://sneezy.cs.nott.ac.uk/fplunch/weblog/?feed=rss2&#038;p=54" rel="self" type="application/rss+xml" />
	<link>http://sneezy.cs.nott.ac.uk/fplunch/weblog/?p=54</link>
	<description>abstracting the pain away</description>
	<lastBuildDate>Tue, 17 May 2011 07:05:56 +0100</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
	<item>
		<title>By: Wouter</title>
		<link>http://sneezy.cs.nott.ac.uk/fplunch/weblog/?p=54#comment-3667</link>
		<dc:creator>Wouter</dc:creator>
		<pubDate>Mon, 12 Feb 2007 11:57:40 +0000</pubDate>
		<guid isPermaLink="false">http://sneezy.cs.nott.ac.uk/fplunch/weblog/?p=54#comment-3667</guid>
		<description>Yep - I&#039;m not the first person to run into this.

I should probably mention that I ran into this after &lt;a href=&quot;http://www.cs.nott.ac.uk/~pwm/&quot; rel=&quot;nofollow&quot;&gt;Peter Morris&lt;/a&gt; talked about strictly positive families, i.e. GADTS that cannot encode recursion in this way. I was curious what this recursion encoding would look like, and was pretty startled when GHC didn&#039;t terminate. I would expect them to limit the number of inline steps to avoid this kind of behaviour.

I don&#039;t entirely agree that this is a completely artificial example. Imagine writing a lambda calculus interpreter using higher-order abstract syntax. If you&#039;re not careful, you can&#039;t write the y-combinator without your compiler diverging:

&lt;tt&gt;
rec f = Lam (\x -&gt; f `apply` (x `apply` x))

y = Lam (\f -&gt; (rec f) `apply` (rec f))
&lt;/tt&gt;

Having a compiler loop is somehow wrong, even if the example is contrived.</description>
		<content:encoded><![CDATA[<p>Yep &#8211; I&#8217;m not the first person to run into this.</p>
<p>I should probably mention that I ran into this after <a href="http://www.cs.nott.ac.uk/~pwm/" rel="nofollow">Peter Morris</a> talked about strictly positive families, i.e. GADTS that cannot encode recursion in this way. I was curious what this recursion encoding would look like, and was pretty startled when GHC didn&#8217;t terminate. I would expect them to limit the number of inline steps to avoid this kind of behaviour.</p>
<p>I don&#8217;t entirely agree that this is a completely artificial example. Imagine writing a lambda calculus interpreter using higher-order abstract syntax. If you&#8217;re not careful, you can&#8217;t write the y-combinator without your compiler diverging:</p>
<p><tt><br />
rec f = Lam (\x -> f `apply` (x `apply` x))</p>
<p>y = Lam (\f -> (rec f) `apply` (rec f))<br />
</tt></p>
<p>Having a compiler loop is somehow wrong, even if the example is contrived.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://sneezy.cs.nott.ac.uk/fplunch/weblog/?p=54#comment-3589</link>
		<dc:creator>Cale Gibbard</dc:creator>
		<pubDate>Fri, 09 Feb 2007 22:23:26 +0000</pubDate>
		<guid isPermaLink="false">http://sneezy.cs.nott.ac.uk/fplunch/weblog/?p=54#comment-3589</guid>
		<description>This behaviour is documented in the GHC manual: http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html

Of course, turning off inlining for apply will fix the problem. You can do that with the pragma:
{-# NOINLINE apply #-}

It would be nice if they could detect and avoid problems of this sort, though I doubt that finding a cleverly efficient solution is a terribly high priority on anyone&#039;s list, seeing as such types only seem to occur in programs contrived to make the compiler unhappy. :) The problem occurs with recursive types which occur contravariantly (i.e. as function parameters) in their own definition -- detecting this directly isn&#039;t entirely trivial due to parametric and mutually recursive types.</description>
		<content:encoded><![CDATA[<p>This behaviour is documented in the GHC manual: <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html" rel="nofollow">http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html</a></p>
<p>Of course, turning off inlining for apply will fix the problem. You can do that with the pragma:<br />
{-# NOINLINE apply #-}</p>
<p>It would be nice if they could detect and avoid problems of this sort, though I doubt that finding a cleverly efficient solution is a terribly high priority on anyone&#8217;s list, seeing as such types only seem to occur in programs contrived to make the compiler unhappy. <img src='http://sneezy.cs.nott.ac.uk/fplunch/weblog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The problem occurs with recursive types which occur contravariantly (i.e. as function parameters) in their own definition &#8212; detecting this directly isn&#8217;t entirely trivial due to parametric and mutually recursive types.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
