Safe Haskell | None |
---|---|
Language | GHC2021 |
Effects.IORef
Description
Provides the MonadIORef
class.
Since: 0.1
Synopsis
- class Monad m => MonadIORef (m :: Type -> Type) where
- newIORef :: HasCallStack => a -> m (IORef a)
- readIORef :: HasCallStack => IORef a -> m a
- writeIORef :: HasCallStack => IORef a -> a -> m ()
- atomicWriteIORef :: HasCallStack => IORef a -> a -> m ()
- modifyIORef' :: HasCallStack => IORef a -> (a -> a) -> m ()
- atomicModifyIORef' :: HasCallStack => IORef a -> (a -> (a, b)) -> m b
- atomicModifyIORef'_ :: (HasCallStack, MonadIORef m) => IORef a -> (a -> a) -> m ()
- data IORef a
Effect
class Monad m => MonadIORef (m :: Type -> Type) where Source #
IORef
effect.
Since: 0.1
Methods
newIORef :: HasCallStack => a -> m (IORef a) Source #
Lifted newIORef
.
Since: 0.1
readIORef :: HasCallStack => IORef a -> m a Source #
Lifted readIORef
.
Since: 0.1
writeIORef :: HasCallStack => IORef a -> a -> m () Source #
Lifted writeIORef
.
Since: 0.1
atomicWriteIORef :: HasCallStack => IORef a -> a -> m () Source #
Lifted atomicWriteIORef
.
Since: 0.1
modifyIORef' :: HasCallStack => IORef a -> (a -> a) -> m () Source #
Lifted modifyIORef'
.
Since: 0.1
atomicModifyIORef' :: HasCallStack => IORef a -> (a -> (a, b)) -> m b Source #
Lifted atomicModifyIORef'
.
Since: 0.1
Instances
MonadIORef IO Source # | Since: 0.1 |
Defined in Effects.IORef Methods newIORef :: HasCallStack => a -> IO (IORef a) Source # readIORef :: HasCallStack => IORef a -> IO a Source # writeIORef :: HasCallStack => IORef a -> a -> IO () Source # atomicWriteIORef :: HasCallStack => IORef a -> a -> IO () Source # modifyIORef' :: HasCallStack => IORef a -> (a -> a) -> IO () Source # atomicModifyIORef' :: HasCallStack => IORef a -> (a -> (a, b)) -> IO b Source # | |
MonadIORef m => MonadIORef (ReaderT e m) Source # | Since: 0.1 |
Defined in Effects.IORef Methods newIORef :: HasCallStack => a -> ReaderT e m (IORef a) Source # readIORef :: HasCallStack => IORef a -> ReaderT e m a Source # writeIORef :: HasCallStack => IORef a -> a -> ReaderT e m () Source # atomicWriteIORef :: HasCallStack => IORef a -> a -> ReaderT e m () Source # modifyIORef' :: HasCallStack => IORef a -> (a -> a) -> ReaderT e m () Source # atomicModifyIORef' :: HasCallStack => IORef a -> (a -> (a, b)) -> ReaderT e m b Source # |
Functions
atomicModifyIORef'_ :: (HasCallStack, MonadIORef m) => IORef a -> (a -> a) -> m () Source #
Atomically apply a function to the contents of an IORef
and return the
old and new values. The result of the function is forced.
Since: 0.1
Reexports
A mutable variable in the IO
monad.
>>>
import Data.IORef
>>>
r <- newIORef 0
>>>
readIORef r
0>>>
writeIORef r 1
>>>
readIORef r
1>>>
atomicWriteIORef r 2
>>>
readIORef r
2>>>
modifyIORef' r (+ 1)
>>>
readIORef r
3>>>
atomicModifyIORef' r (\a -> (a + 1, ()))
>>>
readIORef r
4