<div dir="ltr">I think the point is that by using atomically inside unsafePerformIO you risk using atomically inside atomically; that is, the bad case is atomically inside unsafePerformIO inside atomically. The documentation is wrong in that it only throws an exception when transactions are nested in this way.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 12, 2017 at 12:48 PM, Andrew Martin <span dir="ltr"><<a href="mailto:andrew.thaddeus@gmail.com" target="_blank">andrew.thaddeus@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">This code works, so I don't think that's the case either:<div><br></div><div><div> import Control.Concurrent.STM</div><div> import Data.IORef</div><span class=""><div> import System.IO.Unsafe</div><div> </div><div> main :: IO ()</div><div> main = do</div></span><div> ref <- newIORef (6 :: Int)</div><div> i <- atomically $ do</div><div> var <- newTVar (unsafePerformIO (readIORef ref))</div><div> readTVar var</div><div> print i</div></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Sun, Nov 12, 2017 at 11:28 AM, Henning Thielemann <span dir="ltr"><<a href="mailto:lemming@henning-thielemann.de" target="_blank">lemming@henning-thielemann.de</a><wbr>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
On Sun, 12 Nov 2017, Andrew Martin wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In the stm package, the docs for atomically read:<br>
<br>
> You cannot use 'atomically' inside an 'unsafePerformIO' or > 'unsafeInterleaveIO'. Any attempt to do so will result in a runtime > error. (Reason: allowing this would effectively allow a transaction > inside a transaction, depending on exactly when the thunk is > evaluated.)<br>
</blockquote>
<br></span>
I always thought that it would be the other way round, i.e. that you cannot call 'unsafePerformIO' inside an 'atomically'. Maybe I mixed something up.</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_1633015988168869941gmail_signature" data-smartmail="gmail_signature">-Andrew Thaddeus Martin</div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div>