<div>I agree with what you meant, but not quite with what you said. To be pedantic:</div>
<div> </div>
<div>&gt; import Debug.Trace</div>
<div> </div>
<div>&gt; foo :: Int<br>&gt; foo = trace &quot;Foo&quot; (bar 12)</div>
<div> </div>
<div>&gt; bar :: Int -&gt; Int<br>&gt; bar x = trace &quot;Bar&quot; x</div>
<div> </div>
<div>&gt; main :: IO ()<br>&gt; main = foo `seq` foo `seq` return ()</div>
<div> </div>
<div>main prints &quot;Foo\nBar\n&quot; showing that the bar is only evaluated once, because foo is already evaluated, even though it is referenced twice. So attempting to evaluate foo again just returns the same result.</div>

<div> </div>
<div>
<div>&gt; baz :: Int -&gt; Int<br>&gt; baz x = trace &quot;Baz&quot; (bar x)</div>
<div> </div></div>
<div>&gt; correct :: IO () <br>&gt; correct = baz 10 `seq` baz 11 `seq` return ()</div>
<div> </div>
<div>Though, as you said, call, you probably meant foo was a function, and correct prints &quot;Baz\nBar\nBaz\nBar\n&quot; like you had indicated.</div>
<div> </div>
<div>But pedantically even the function:</div>
<div> </div>
<div>&gt; quux :: Int -&gt; Int<br>&gt; quux x = trace &quot;Quux&quot; (bar 12) 
<div> </div>
<div>&gt; optmain :: IO () <br>&gt; optmain = quux 10 `seq` quux 11 `seq` return ()</div></div>
<div> </div>
<div>might print only once if GHC at the optimization level selected recognizes that quux doesn&#39;t depend on its argument and rewrote your code with more sharing.</div>
<div> </div>
<div>-Edward Kmett</div>
<div> </div>
<div class="gmail_quote">On Sun, Sep 13, 2009 at 7:45 PM, Mark Wotton <span dir="ltr">&lt;<a href="mailto:mwotton@gmail.com">mwotton@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im"><br>On 14/09/2009, at 9:28 AM, Casey Hawthorne wrote:<br><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Do I have this right?  &quot;Remembering&quot;  Memoization!<br><br>For some applications, a lot of state does not to be saved, since<br>
&quot;initialization&quot; functions can be called early, and these functions<br>will &quot;remember&quot; - (memoize) their results when called again, because<br>of lazy evaluation?<br></blockquote><br></div>You don&#39;t get memoisation for free.<br>
If you define a variable once in a where block, it&#39;s true that you&#39;ll evaluate it at most once, but if you repeatedly call a function &quot;foo&quot; that then calls &quot;bar 12&quot; each time, &quot;bar 12&quot; will be evaluated once per &quot;foo&quot; call.<br>
<br>Cheers<br><font color="#888888">Mark</font> 
<div>
<div></div>
<div class="h5"><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><br>