| Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 Kowainik |
|---|---|
| License | MIT |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Stability | Stable |
| Portability | Portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Relude.Lifted.IORef
Description
Lifted reexports from Data.IORef module.
Synopsis
- data IORef a
- atomicModifyIORef :: MonadIO m => IORef a -> (a -> (a, b)) -> m b
- atomicModifyIORef' :: MonadIO m => IORef a -> (a -> (a, b)) -> m b
- atomicModifyIORef_ :: MonadIO m => IORef a -> (a -> a) -> m ()
- atomicModifyIORef'_ :: MonadIO m => IORef a -> (a -> a) -> m ()
- atomicWriteIORef :: MonadIO m => IORef a -> a -> m ()
- modifyIORef :: MonadIO m => IORef a -> (a -> a) -> m ()
- modifyIORef' :: MonadIO m => IORef a -> (a -> a) -> m ()
- newIORef :: MonadIO m => a -> m (IORef a)
- readIORef :: MonadIO m => IORef a -> m a
- writeIORef :: MonadIO m => IORef a -> a -> m ()
Documentation
A mutable variable in the IO monad.
>>>import GHC.Internal.Data.IORef>>>r <- newIORef 0>>>readIORef r0>>>writeIORef r 1>>>readIORef r1>>>atomicWriteIORef r 2>>>readIORef r2>>>modifyIORef' r (+ 1)>>>readIORef r3>>>atomicModifyIORef' r (\a -> (a + 1, ()))>>>readIORef r4
Instances
| NFData1 IORef | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| NFData (IORef a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
| Eq (IORef a) | Pointer equality. @since base-4.0.0.0 |
atomicModifyIORef :: MonadIO m => IORef a -> (a -> (a, b)) -> m b Source #
Lifted version of atomicModifyIORef.
>>>ref <- newIORef 42>>>atomicModifyIORef ref (\a -> (a, a + 3))45>>>readIORef ref42
- To avoid space-leaks, see
atomicModifyIORef'for stricter updates - If you are not interested in the return value, see
atomicModifyIORef_
atomicModifyIORef' :: MonadIO m => IORef a -> (a -> (a, b)) -> m b Source #
Lifted version of atomicModifyIORef'.
>>>ref <- newIORef 42>>>atomicModifyIORef' ref (\a -> (a, a + 3))45>>>readIORef ref42
- For lazier updates, see
atomicModifyIORef - If you are not interested in the return value, see
atomicModifyIORef'_
atomicModifyIORef_ :: MonadIO m => IORef a -> (a -> a) -> m () Source #
Version of atomicModifyIORef that discards return value. Useful
when you want to update IORef but not interested in the returning
result.
>>>ref <- newIORef 42>>>atomicModifyIORef_ ref (`div` 2)>>>readIORef ref21
Since: 0.7.0.0
atomicModifyIORef'_ :: MonadIO m => IORef a -> (a -> a) -> m () Source #
Version of atomicModifyIORef' that discards return value. Useful
when you want to update IORef but not interested in the returning
result.
>>>ref <- newIORef 42>>>atomicModifyIORef'_ ref (`div` 2)>>>readIORef ref21
Since: 0.7.0.0
atomicWriteIORef :: MonadIO m => IORef a -> a -> m () Source #
Lifted version of atomicWriteIORef.
>>>ref <- newIORef 42>>>atomicWriteIORef ref 45>>>readIORef ref45
modifyIORef :: MonadIO m => IORef a -> (a -> a) -> m () Source #
Lifted version of modifyIORef.
>>>ref <- newIORef 42>>>modifyIORef ref (\a -> a + 6)>>>readIORef ref48
- To avoid space-leaks, see
modifyIORef'for stricter updates - For atomic updates, see
atomicModifyIORef
modifyIORef' :: MonadIO m => IORef a -> (a -> a) -> m () Source #
Lifted version of modifyIORef'.
>>>ref <- newIORef 42>>>modifyIORef' ref (\a -> a + 3)>>>readIORef ref45
- For lazier updates, see
modifyIORef - For atomic updates, see
atomicModifyIORef'
newIORef :: MonadIO m => a -> m (IORef a) Source #
Lifted version of newIORef.
>>>ref <- newIORef False>>>:t refref :: IORef Bool
readIORef :: MonadIO m => IORef a -> m a Source #
Lifted version of readIORef.
>>>ref <- newIORef 42>>>readIORef ref42
writeIORef :: MonadIO m => IORef a -> a -> m () Source #
Lifted version of writeIORef.
>>>ref <- newIORef 42>>>writeIORef ref 43>>>readIORef ref43