Sorry for the last mail, I now tried it and it returns the next value every time I call it.<br><br>I was using an unsafeperformIO trick somewhere, and that fas the one resulting in the previously described behaviour.<br><br>
You can just ignore the previous mail. <br><br><div class="gmail_quote">2009/12/17 Ozgur Akgun <span dir="ltr">&lt;<a href="mailto:ozgurakgun@gmail.com">ozgurakgun@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Maybe not related, but does the following prove next is called once and only once.<br><br><br><span style="font-family: courier new,monospace;">import qualified Data.ByteString as BS</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">import qualified Data.ByteString.Char8 as BSC</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">next =</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        nextcache &lt;- BS.readFile &quot;next.cache&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        let nextint = readInt (BSC.unpack nextcache)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        BS.writeFile &quot;next.cache&quot; (BSC.pack (show (nextint+1)))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        return nextint</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">readInt :: String -&gt; Int</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">readInt = read</span><br><br><br>I put a single character, 1 in the file &quot;next.cache&quot; when I run this through ghci, and call next several times, I always get a 1. Whereas in the file there is a 2.<br>

I see that next is a trial of creating a function which returns different things everytime its called, but it&#39;s in the IO monad, so that should be doable.<br><br>When I re-run ghci, now it starts to give 2 everytime I call it. Does that mean, it doesn&#39;t bother to re-read the file while we are in the same process.<br>

<br><br>Hope it relates to the OP&#39;s question in some way :)<br><br>Best,<br><br><div class="gmail_quote">2009/12/16 Daniel Fischer <span dir="ltr">&lt;<a href="mailto:daniel.is.fischer@web.de" target="_blank">daniel.is.fischer@web.de</a>&gt;</span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Am Mittwoch 16 Dezember 2009 15:49:54 schrieb michael rice:<br>
<div>&gt; Thanks all,<br>
&gt;<br>
&gt; OK, so this definition of fib<br>
&gt;<br>
&gt; fib 0 = 1<br>
&gt; fib 1 = 1<br>
&gt; fib n = fib (n-1) + fib (n-2)<br>
&gt;<br>
&gt; would involve a lot of recomputation for some large n,<br>
<br>
</div>Where &quot;large&quot; can start as low as 20; 60 would be out of reach.<br>
<br>
&gt; which memoization would eliminate?<br>
<br>
Right.<br>
&gt;<br>
&gt; Michael<br>
<div><div></div><div><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>
</div></div></blockquote></div></div></div><br><br clear="all"><br>-- <br><font color="#888888">Ozgur Akgun<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Ozgur Akgun<br>