{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude #-}
module System.IO.Unsafe (
unsafePerformIO,
unsafeDupablePerformIO,
unsafeInterleaveIO,
unsafeFixIO,
) where
import GHC.Base
import GHC.IO
import GHC.IORef
import GHC.Exception
import Control.Exception
unsafeFixIO :: (a -> IO a) -> IO a
unsafeFixIO :: (a -> IO a) -> IO a
unsafeFixIO k :: a -> IO a
k = do
IORef a
ref <- a -> IO (IORef a)
forall a. a -> IO (IORef a)
newIORef (NonTermination -> a
forall a e. Exception e => e -> a
throw NonTermination
NonTermination)
a
ans <- IO a -> IO a
forall a. IO a -> IO a
unsafeDupableInterleaveIO (IORef a -> IO a
forall a. IORef a -> IO a
readIORef IORef a
ref)
a
result <- a -> IO a
k a
ans
IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef a
ref a
result
a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
result