|
Packit |
1d883e |
{-# LANGUAGE CPP #-}
|
|
Packit |
1d883e |
{-# LANGUAGE NoImplicitPrelude #-}
|
|
Packit |
1d883e |
{-# LANGUAGE FlexibleContexts #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
#if __GLASGOW_HASKELL__ >= 704
|
|
Packit |
1d883e |
{-# LANGUAGE Safe #-}
|
|
Packit |
1d883e |
#endif
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
{- |
|
|
Packit |
1d883e |
Module : Data.IORef
|
|
Packit |
1d883e |
Copyright : Liyang HU, Bas van Dijk
|
|
Packit |
1d883e |
License : BSD-style
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>
|
|
Packit |
1d883e |
Stability : experimental
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
This is a wrapped version of "Data.IORef" with types
|
|
Packit |
1d883e |
generalised from 'IO' to all monads in 'MonadBase'.
|
|
Packit |
1d883e |
-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
module Data.IORef.Lifted
|
|
Packit |
1d883e |
( IORef
|
|
Packit |
1d883e |
, newIORef
|
|
Packit |
1d883e |
, readIORef
|
|
Packit |
1d883e |
, writeIORef
|
|
Packit |
1d883e |
, modifyIORef
|
|
Packit |
1d883e |
#if MIN_VERSION_base(4,6,0)
|
|
Packit |
1d883e |
, modifyIORef'
|
|
Packit |
1d883e |
#endif
|
|
Packit |
1d883e |
, atomicModifyIORef
|
|
Packit |
1d883e |
#if MIN_VERSION_base(4,6,0)
|
|
Packit |
1d883e |
, atomicModifyIORef'
|
|
Packit |
1d883e |
, atomicWriteIORef
|
|
Packit |
1d883e |
#endif
|
|
Packit |
1d883e |
, mkWeakIORef
|
|
Packit |
1d883e |
) where
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
--------------------------------------------------------------------------------
|
|
Packit |
1d883e |
-- Imports
|
|
Packit |
1d883e |
--------------------------------------------------------------------------------
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- from base:
|
|
Packit |
1d883e |
import Data.IORef ( IORef )
|
|
Packit |
1d883e |
import qualified Data.IORef as R
|
|
Packit |
1d883e |
import System.IO ( IO )
|
|
Packit |
1d883e |
import System.Mem.Weak ( Weak )
|
|
Packit |
1d883e |
import Prelude ( (.) )
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- from transformers-base:
|
|
Packit |
1d883e |
import Control.Monad.Base ( MonadBase, liftBase )
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- from monad-control:
|
|
Packit |
1d883e |
import Control.Monad.Trans.Control ( MonadBaseControl, liftBaseDiscard )
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
#include "inlinable.h"
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
--------------------------------------------------------------------------------
|
|
Packit |
1d883e |
-- * IORefs
|
|
Packit |
1d883e |
--------------------------------------------------------------------------------
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.newIORef'.
|
|
Packit |
1d883e |
newIORef :: MonadBase IO m => a -> m (IORef a)
|
|
Packit |
1d883e |
newIORef = liftBase . R.newIORef
|
|
Packit |
1d883e |
{-# INLINABLE newIORef #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.readIORef'.
|
|
Packit |
1d883e |
readIORef :: MonadBase IO m => IORef a -> m a
|
|
Packit |
1d883e |
readIORef = liftBase . R.readIORef
|
|
Packit |
1d883e |
{-# INLINABLE readIORef #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.writeIORef'.
|
|
Packit |
1d883e |
writeIORef :: MonadBase IO m => IORef a -> a -> m ()
|
|
Packit |
1d883e |
writeIORef r = liftBase . R.writeIORef r
|
|
Packit |
1d883e |
{-# INLINABLE writeIORef #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.modifyIORef'.
|
|
Packit |
1d883e |
modifyIORef :: MonadBase IO m => IORef a -> (a -> a) -> m ()
|
|
Packit |
1d883e |
modifyIORef r = liftBase . R.modifyIORef r
|
|
Packit |
1d883e |
{-# INLINABLE modifyIORef #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.atomicModifyIORef'.
|
|
Packit |
1d883e |
atomicModifyIORef :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b
|
|
Packit |
1d883e |
atomicModifyIORef r = liftBase . R.atomicModifyIORef r
|
|
Packit |
1d883e |
{-# INLINABLE atomicModifyIORef #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
#if MIN_VERSION_base(4,6,0)
|
|
Packit |
1d883e |
-- | Generalized version of 'R.modifyIORef''.
|
|
Packit |
1d883e |
modifyIORef' :: MonadBase IO m => IORef a -> (a -> a) -> m ()
|
|
Packit |
1d883e |
modifyIORef' r = liftBase . R.modifyIORef' r
|
|
Packit |
1d883e |
{-# INLINABLE modifyIORef' #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.atomicModifyIORef''.
|
|
Packit |
1d883e |
atomicModifyIORef' :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b
|
|
Packit |
1d883e |
atomicModifyIORef' r = liftBase . R.atomicModifyIORef' r
|
|
Packit |
1d883e |
{-# INLINABLE atomicModifyIORef' #-}
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.atomicWriteIORef'.
|
|
Packit |
1d883e |
atomicWriteIORef :: MonadBase IO m => IORef a -> a -> m ()
|
|
Packit |
1d883e |
atomicWriteIORef r = liftBase . R.atomicWriteIORef r
|
|
Packit |
1d883e |
#endif
|
|
Packit |
1d883e |
|
|
Packit |
1d883e |
-- | Generalized version of 'R.mkWeakIORef'.
|
|
Packit |
1d883e |
--
|
|
Packit |
1d883e |
-- Note any monadic side effects in @m@ of the \"finalizer\" computation
|
|
Packit |
1d883e |
-- are discarded.
|
|
Packit |
1d883e |
mkWeakIORef :: MonadBaseControl IO m => IORef a -> m () -> m (Weak (IORef a))
|
|
Packit |
1d883e |
mkWeakIORef = liftBaseDiscard . R.mkWeakIORef
|
|
Packit |
1d883e |
{-# INLINABLE mkWeakIORef #-}
|