Safe Haskell | Safe-Inferred |
---|
- type Ref m a = MLens m () a
- readRef :: Monad m => MLens m () a -> m a
- writeRef :: Monad m => Ref m a -> a -> m ()
- modRef :: Monad m => Ref m a -> (a -> a) -> m ()
- fileRef :: FilePath -> IO (Ref IO String)
- fileRef_ :: FilePath -> IO (Ref IO (Maybe String))
- logConsoleLens :: Show a => MLens IO a a
- logMLens :: Monad m => (a -> m ()) -> (a -> m ()) -> MLens m a a
- logFile :: FilePath -> IO (String -> IO ())
Data type for reference lenses
type Ref m a = MLens m () aSource
Note that references lenses can be composed with lenses. For example, if
r :: Ref m (a,b)
then
fstLens . r :: Ref m a
Reference laws for pure references:
-
(readRef r)
has no side effect. *(readRef r >>= writeRef r)
has no side effect. *(writeRef r a >> readRef r)
returnsa
. *(writeRef r a >> writeRef r a)
has the same effect as(writeRef r a)
.
Reference operations
Some IO
referenceses
fileRef :: FilePath -> IO (Ref IO String)Source
Using fileRef
is safe if the file is not used concurrently.
fileRef_ :: FilePath -> IO (Ref IO (Maybe String))Source
Note that if you write Nothing
, the file is deleted.
logConsoleLens :: Show a => MLens IO a aSource
logConsoleLens
logs elementary get and set operations.
Note that with the current representation of MLens
, every set operation involves a get operation.