<div dir="ltr">Thanks.  This helps.  I was right to mistrust the unsafePerformIO "solution".  :-)  What Haskell was telling me is that I need to think about the scope of the identifiers I'm allocating, and what guarantees I'm making.<div>
<br><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 17, 2014 at 10:26 AM, Danny Gratzer <span dir="ltr"><<a href="mailto:danny.gratzer@gmail.com" target="_blank">danny.gratzer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">New `MVar` has to return a different memory location every time and this is noticeable, it's not referentially transparent.<div>
<br></div><div>Consider what would happen if we made the transformation</div>

<div><br></div><div>     let a = newMVar 0</div><div>     let b = newMVar 0</div><div>     putMVar a 1</div><div>     readMVar b<br><div class="gmail_extra"><br></div><div class="gmail_extra">to</div><div class="gmail_extra">


<br></div><div class="gmail_extra">    let a = newMVar 0</div><div class="gmail_extra">         b = a</div><div class="gmail_extra">     ...</div><div class="gmail_extra"><br></div><div class="gmail_extra">If newMVar was referentially transparent, we can automatically share any of it's calls with same arguments since they're supposed to return the same thing everytime. Since it's not referentially transparent, back into the IO monad it goes.</div>


<div class="gmail_extra"><br></div><div class="gmail_extra">Also if you do that toplevel counter trick, you want NoInline otherwise GHC might just inline it at each occurrence and you'll end up with separate counters.<br clear="all">


<div><div dir="ltr"><div><br></div>Cheers,<div>Danny Gratzer</div></div></div></div></div></div>
</blockquote></div><br></div>