<br><br><div><span class="gmail_quote">On 6/16/08, <b class="gmail_sendername">Magicloud Magiclouds</b> &lt;<a href="mailto:magicloud.magiclouds@gmail.com">magicloud.magiclouds@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>&nbsp;&nbsp;&nbsp; I am getting familiar with FP now, and I have a &quot;program design&quot; kind of question.<br>&nbsp;&nbsp;&nbsp; Say I have something like this in C:<br>static int old;<br>int diff (int now) { /* this would be called once a second */<br>

&nbsp; int ret = now - old;<br>&nbsp; old = now;<br>&nbsp; return ret;<br>}<br>&nbsp; &nbsp; Because there is no &quot;variable&quot; in Haskell. So how to do this in a FP way?</blockquote></div><p></p><p>The short answer is that your question amounts to &quot;How do I do imperative programming in an FP way&quot;, to which the answer is &quot;you really should try to avoid it&quot;.</p>
<p>Longer answer:</p><p>I think you&#39;ll be bette served if you describe your problem on a much higher level than this. Chances are that if you write your program in an FP way, you wouldn&#39;t need a function like your diff.</p>
<p>That said, Haskell do have variables (in this case an IORef would do what you want), but again, you probably don&#39;t want that, so if you post what problem you&#39;re trying to solve using &quot;diff&quot;, then it will be easier to help you design it in an FP way. Doing things in an FP way tend to impact your program a lot more than just some minor changes to the functions at the &quot;bottom&quot;, it will change the whole design.<br>
</p><p>--<br></p>Sebastian Sylvan<br>+44(0)7857-300802<br>UIN: 44640862