<HTML>
<HEAD>
<TITLE>Re: [Haskell-cafe] Multiple State Monads</TITLE>
</HEAD>
<BODY>
<FONT SIZE="4"><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
On 16/01/2009 01:28, &quot;Luke Palmer&quot; &lt;lrpalmer@gmail.com&gt; wrote:<BR>
<BR>
</SPAN></FONT></FONT><BLOCKQUOTE><BLOCKQUOTE><FONT SIZE="4"><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Compile-time constants could be handled by simple top-level bindings. &nbsp;This technique is specifically for the case you are after:<BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><FONT FACE="Courier New"><BR>
</FONT></SPAN><FONT FACE="Courier New"><SPAN STYLE='font-size:10pt'>mcSimulate :: Double -&gt; Double -&gt; Word64 -&gt; [Double]<BR>
mcSimulate startStock endTime seedForSeed = go seedForSeed<BR>
</SPAN></FONT></FONT><FONT FACE="Courier New"><FONT SIZE="5"><SPAN STYLE='font-size:12pt'> &nbsp;</SPAN></FONT><FONT SIZE="4"><SPAN STYLE='font-size:11pt'>where<BR>
&nbsp;&nbsp;&nbsp;&nbsp;go = fst expiryStock : go newSeedForSeed<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where<BR>
</SPAN></FONT><FONT SIZE="5"><SPAN STYLE='font-size:12pt'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN></FONT><FONT SIZE="4"><SPAN STYLE='font-size:10pt'>expiryStock = iterate evolveUnderlying (startStock, ranq1Init seedForSeed) <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!! truncate (endTime/timeStep)<BR>
</SPAN></FONT><FONT SIZE="5"><SPAN STYLE='font-size:12pt'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN></FONT><FONT SIZE="4"><SPAN STYLE='font-size:10pt'>newSeedForSeed = seedForSeed + 246524<BR>
</SPAN></FONT></FONT><FONT SIZE="4"><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'> <BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><FONT FACE="Courier New">See what's going on there?<BR>
<BR>
I don't know about that nested where. &nbsp;In Real Life I would probably use a let instead for expiryStock and newSeedForSeed.<BR>
<BR>
Luke<BR>
</FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><BR>
Ahh, I get it now, that&#8217;s pretty neat - &#8216;go&#8217; is only updating the seedForSeed and the expiryStock, the inner &#8216;where&#8217; clause keeps everything else constant each time it is called.<BR>
</FONT></SPAN></FONT></BLOCKQUOTE></BLOCKQUOTE><FONT SIZE="4"><SPAN STYLE='font-size:11pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><BR>
Thanks again!<BR>
<BR>
Phil.<BR>
</FONT></SPAN></FONT>
</BODY>
</HTML>