<div class="gmail_quote">On Thu, Jan 22, 2009 at 5:48 AM, Ertugrul Soeylemez <span dir="ltr"><<a href="mailto:es@ertes.de">es@ertes.de</a>></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 <<a href="mailto:lrpalmer@gmail.com">lrpalmer@gmail.com</a>> wrote:<br>
<br>
> TVars are overkill here, actually, an IORef would be just fine, I<br>
> think.<br>
<br>
</div>Using IORefs is generally a sign of bad style. </blockquote><div><br></div><div>I totally disagree. </div><div><br></div><div>The disadvantage of IORefs is that they do not work together very nicely. 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. You will <span class="Apple-style-span" style="font-style: italic;">never</span> have to use it with any other IORef, because nobody else even knows it exists. 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> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> But MVars would<br>
perfectly suffice here. They would be essentially the same, but without<br>
'atomically'.</blockquote></div>