{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
module Data.IORef.Lifted
( IORef
, newIORef
, readIORef
, writeIORef
, modifyIORef
#if MIN_VERSION_base(4,6,0)
, modifyIORef'
#endif
, atomicModifyIORef
#if MIN_VERSION_base(4,6,0)
, atomicModifyIORef'
, atomicWriteIORef
#endif
, mkWeakIORef
) where
import Control.Monad.Base.Control ( MonadBaseControl, liftBaseDiscard )
import Data.Basic ( Basic1 (..) )
import Data.IORef ( IORef )
import qualified Data.IORef as R
import System.IO ( IO )
import System.Mem.Weak ( Weak )
import Prelude ( (.) )
#include "inlinable.h"
newIORef :: (Basic1 m, Base m ~ IO) => a -> m (IORef a)
newIORef = liftBase . R.newIORef
{-# INLINABLE newIORef #-}
readIORef :: (Basic1 m, Base m ~ IO) => IORef a -> m a
readIORef = liftBase . R.readIORef
{-# INLINABLE readIORef #-}
writeIORef :: (Basic1 m, Base m ~ IO) => IORef a -> a -> m ()
writeIORef r = liftBase . R.writeIORef r
{-# INLINABLE writeIORef #-}
modifyIORef :: (Basic1 m, Base m ~ IO) => IORef a -> (a -> a) -> m ()
modifyIORef r = liftBase . R.modifyIORef r
{-# INLINABLE modifyIORef #-}
atomicModifyIORef :: (Basic1 m, Base m ~ IO) => IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef r = liftBase . R.atomicModifyIORef r
{-# INLINABLE atomicModifyIORef #-}
#if MIN_VERSION_base(4,6,0)
modifyIORef' :: (Basic1 m, Base m ~ IO) => IORef a -> (a -> a) -> m ()
modifyIORef' r = liftBase . R.modifyIORef' r
{-# INLINABLE modifyIORef' #-}
atomicModifyIORef' :: (Basic1 m, Base m ~ IO) => IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef' r = liftBase . R.atomicModifyIORef' r
{-# INLINABLE atomicModifyIORef' #-}
atomicWriteIORef :: (Basic1 m, Base m ~ IO) => IORef a -> a -> m ()
atomicWriteIORef r = liftBase . R.atomicWriteIORef r
#endif
mkWeakIORef :: (MonadBaseControl m, Base m ~ IO) => IORef a -> m () -> m (Weak (IORef a))
mkWeakIORef = liftBaseDiscard . R.mkWeakIORef
{-# INLINABLE mkWeakIORef #-}