<div class="gmail_quote">On Thu, Jan 22, 2009 at 5:48 AM, Ertugrul Soeylemez <span dir="ltr">&lt;<a href="mailto:es@ertes.de">es@ertes.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="Ih2E3d">Luke Palmer &lt;<a href="mailto:lrpalmer@gmail.com">lrpalmer@gmail.com</a>&gt; wrote:<br>
<br>
&gt; TVars are overkill here, actually, an IORef would be just fine, I<br>
&gt; think.<br>
<br>
</div>Using IORefs is generally a sign of bad style. </blockquote><div><br></div><div>I totally disagree.&nbsp;</div><div><br></div><div>The disadvantage of IORefs is that they do not work together very nicely. &nbsp;If you have more than one, it is very hard (impossible) to keep multithreaded invariants between them.</div>
<div><br></div><div>But in this case, the IORef is completely encapsulated: it does not leave the scope in which it was created. &nbsp;You will <span class="Apple-style-span" style="font-style: italic;">never</span>&nbsp;have to use it with any other IORef, because nobody else even knows it exists. &nbsp;The pattern is self-contained and threadsafe with just an IORef.</div>
<div><br></div><div>A program that needs only IORefs and is threadsafe is *good* style to me, because it means all the state is well-encapsulated (if it escaped, it would fail to be threadsafe).</div><div><br></div><div>Luke</div>
<div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">&nbsp;But MVars would<br>
perfectly suffice here. &nbsp;They would be essentially the same, but without<br>
&#39;atomically&#39;.</blockquote></div>