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.On Thu, Apr 17, 2014 at 10:26 AM, Danny Gratzer <danny.gratzer@gmail.com> wrote:
New `MVar` has to return a different memory location every time and this is noticeable, it's not referentially transparent.Consider what would happen if we made the transformationlet a = newMVar 0let b = newMVar 0putMVar a 1readMVar btolet a = newMVar 0b = a...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.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.
Cheers,Danny Gratzer
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe