<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>