Copyright | Copyright (c) 2012-2015, David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Tested with: GHC 7.10.1
The module defines a shared mutable reference accessible from different threads.
- data MRef a
- newMRef :: a -> IO (MRef a)
- readMRef :: MRef a -> IO a
- maybeReadMRef :: b -> (a -> IO b) -> MRef (Maybe a) -> IO b
- writeMRef :: MRef a -> a -> IO ()
- maybeWriteMRef :: MRef (Maybe a) -> IO a -> (a -> IO b) -> IO b
- modifyMRef_ :: MRef a -> (a -> IO a) -> IO ()
- modifyMRef :: MRef a -> (a -> IO (a, b)) -> IO b
- withMRef :: MRef a -> (a -> IO b) -> IO b
Documentation
maybeReadMRef :: b -> (a -> IO b) -> MRef (Maybe a) -> IO b Source
Like maybe
but for the shared reference under assumption
that the reference is updated only once by its initial value.
maybeWriteMRef :: MRef (Maybe a) -> IO a -> (a -> IO b) -> IO b Source
Update the contents if the reference was empty and then return a result of applying the specified function to either the initial or current value.
modifyMRef_ :: MRef a -> (a -> IO a) -> IO () Source
Modify the contents of the shared reference.
modifyMRef :: MRef a -> (a -> IO (a, b)) -> IO b Source
Modify the contents of the shared reference but allow returning the result.