
This code works, so I don't think that's the case either: import Control.Concurrent.STM import Data.IORef import System.IO.Unsafe main :: IO () main = do ref <- newIORef (6 :: Int) i <- atomically $ do var <- newTVar (unsafePerformIO (readIORef ref)) readTVar var print i On Sun, Nov 12, 2017 at 11:28 AM, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Sun, 12 Nov 2017, Andrew Martin wrote:
In the stm package, the docs for atomically read:
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.)
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.
-- -Andrew Thaddeus Martin