Hello Mattias,<br><br>I think you will find this thread from the haskell-cafe mailing list quite helpful. <br>&nbsp; Re: [Haskell-cafe] Memoization&nbsp; <br>&nbsp; <a href="http://www.mail-archive.com/haskell-cafe@haskell.org/msg09924.html">http://www.mail-archive.com/haskell-cafe@haskell.org/msg09924.html</a><br>
<br>Also, the Haskell wiki contains comments about techniques for memoization along with references at the bottom.<br>&nbsp; Haskell wiki Memoization:<br>&nbsp; <a href="http://www.haskell.org/haskellwiki/Memoization">http://www.haskell.org/haskellwiki/Memoization</a><br>
<br>Hope that helps.<br>__<br>Donnie Jones<br><br><div class="gmail_quote">On Thu, Dec 11, 2008 at 10:18 AM, Mattias Bengtsson <span dir="ltr">&lt;<a href="mailto:moonlite@dtek.chalmers.se">moonlite@dtek.chalmers.se</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;">The program below computes (f 27) almost instantly but if i replace the<br>
definition of (f n) below with (f n = f (n - 1) * f (n -1)) then it<br>
takes around 12s to terminate. I realize this is because the original<br>
version caches results and only has to calculate, for example, (f 25)<br>
once instead of (i guess) four times.<br>
There is probably a good reason why this isn&#39;t caught by the compiler.<br>
But I&#39;m interested in why. Anyone care to explain?<br>
<br>
&gt; main = print (f 27)<br>
&gt;<br>
&gt; f 0 = 1<br>
&gt; f n = let f&#39; = f (n-1)<br>
&gt; &nbsp; &nbsp; &nbsp; in f&#39; * f&#39;<br>
<br>
(compiled with ghc --make -O2)<br>
<br>
Mattias<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>