<div class="gmail_quote">On Wed, Feb 25, 2009 at 10:38 AM, Dusan Kolar <span dir="ltr">&lt;<a href="mailto:kolar@fit.vutbr.cz">kolar@fit.vutbr.cz</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
 I have a function a computation of which is quite expensive, it is recursively dependent on itself with respect to some other function values - we can roughly model its behaviour with fib function (returns n-th number of Fibonacci&#39;s sequence). Unfortunately, it is not fib, it is far more complicated. Nevertheless, for demonstration of my question/problem I will use fib, it&#39;s quite good.</blockquote>
<div><br></div><div>I suggest using <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-memocombinators">data-memocombinators</a> for this rather than rolling your own.  It accomplishes the same thing, but makes the choice of memo structure independent of the code that uses it (and Memo.integral has asymptotically better performance than a list).</div>
<div><br></div><div>Luke</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<br>
 I want to store results in a list (array, with its strong size limit that I do not know prior to computation, is not suitable) and then pick them up using (!!) operator. Well, if the list is &quot;global&quot; function/constant then it works quite well. Unfortunately, this is not, what I would like to have. Nevertheless, local version does not work.<br>

<br>
 Could someone point me to some text that explains it? Memoization text on wiki does not seem to be helpful. Time/operation consumption is deduced from number of reductions reported by hugs and winhugs (tested both on Linux and Windows).<br>

<br>
 Thank you for hints,<br>
<br>
  Dusan<br>
<br>
<br>
P.S.<br>
Code I used for testing.<br>
<br>
module Testmemo<br>
   (  fibW<br>
   ,  fibL<br>
   ,  fibM<br>
   )  where<br>
<br>
<br>
fibW m = allfib !! m<br>
 where<br>
   allfib = 0:1:[allfib!!n + allfib!!(n+1) | n &lt;- [0..]]<br>
<br>
<br>
fibL m =<br>
 let<br>
   allfib = 0:1:[allfib!!n + allfib!!(n+1) | n &lt;- [0..]]<br>
 in allfib !! m<br>
<br>
<br>
fibM n = myallfib !! n<br>
myallfib = 0:1:[myallfib!!n + myallfib!!(n+1) | n &lt;- [0..]]<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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>