<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">In my experience [1], observable sharing using GHC&#39;s stable names is a pretty effective solution to this problem.</blockquote>

<div><br>Plus unsafePerformIO and weak references as in <i><a href="http://citeseer.ist.psu.edu/peytonjones99stretching.html">Stretching the storage
    manager: weak pointers and stable names in Haskell</a></i>?<br><br>Lacking a more elegant alternative, that&#39;s what I&#39;ll probably do again, as in Pan, Vertigo, and Pajama.<br><br>  - Conal<br></div><br><div class="gmail_quote">

On Wed, May 27, 2009 at 3:51 AM, Sittampalam, Ganesh <span dir="ltr">&lt;<a href="mailto:ganesh.sittampalam@credit-suisse.com">ganesh.sittampalam@credit-suisse.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div></div><div class="h5">Sebastiaan Visser wrote:<br>
&gt; On May 27, 2009, at 1:49 AM, Conal Elliott wrote:<br>
&gt;&gt; Hi Tom,<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve been working on another code-generating graphics compiler,<br>
&gt;&gt; generating GPU code.  As always, I run into the problem of efficient<br>
&gt;&gt; common subexpression elimination.  In Pan, Vertigo &amp; Pajama, I used<br>
&gt;&gt; lazy memoization, using stable pointers and weak references, to avoid<br>
&gt;&gt; the worst-case-exponential behavior you mention below.  I&#39;m now using<br>
&gt;&gt; a bottom-up CSE method that&#39;s slower and more complicated than I&#39;m<br>
&gt;&gt; going for.<br>
&gt;<br>
&gt; What do you mean with `exponential behavior&#39;? Exponential related to<br>
&gt; what?<br>
&gt;<br>
&gt; For my FRP EDSL to JavaScript (toy) compiler[1] I&#39;ve been<br>
&gt; implementing CSE as well. I traverses the expression tree recursively<br>
&gt; and creates an small intermediate language containing id&#39;s (pointers)<br>
&gt; to expressions instead of real sub-expressions.<br>
&gt;<br>
&gt; Maybe (probably) I am very naive, but I think this trick takes time<br>
&gt; linear to the amount of sub-expressions in my script. When using a<br>
&gt; trie instead of a binary tree for the comparisons there should be no<br>
&gt; more character (or atomic expression) comparisons that the amount of<br>
&gt; characters in the script.<br>
&gt;<br>
&gt; So the problem seems not to be CSE algorithm, but the fact that EDSL<br>
&gt; itself tends to blow up because it is hosted in Haskell. Like Tom&#39;s<br>
&gt; example:<br>
&gt;<br>
&gt;  &gt; let d = Add c c<br>
&gt;  &gt;     e = Add d d    -- &quot;e&quot; now as 16 leaf nodes.<br>
&gt;<br>
&gt; But again, I might be missing some important point here.<br>
<br>
</div></div>That&#39;s exactly right. But it&#39;s pretty inconvenient to have your<br>
expression tree to blow up exponentially in relation to the code the<br>
user actually wrote! You can indeed construct an intermediate language<br>
that collapses this blowup, but the pass to create it must take<br>
exponential time if written completely purely, since it has to visit<br>
everything at least once.<br>
<br>
In my experience [1], observable sharing using GHC&#39;s stable names is a<br>
pretty effective solution to this problem.<br>
<br>
Ganesh<br>
<br>
[1] <a href="http://www.earth.li/%7Eganesh/research/paradise-icfp08/" target="_blank">http://www.earth.li/~ganesh/research/paradise-icfp08/</a><br>
<br>
===============================================================================<br>
 Please access the attached hyperlink for an important electronic communications disclaimer:<br>
 <a href="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html" target="_blank">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</a><br>
 ===============================================================================<br>
<br>
</blockquote></div><br>