lgtk-0.3: lens-based GUI with Gtk backend

Safe HaskellSafe-Inferred

Data.MLens.Ref

Contents

Synopsis

Documentation

data Unit Source

The abstract data type Unit is isomorphic to (), but by making it abstract we can prevent using references on the left hand side of lens composition.

Instances

Data type for reference lenses

type Ref m a = MLens m Unit 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 >> return ()) === (return ())
  • (readRef r >>= writeRef r) === (return ())
  • (writeRef r a >> readRef r) === (return a)
  • (writeRef r a >> writeRef r a') === (writeRef r a')

These laws are equivalent to the get-no-effect, set-get, get-set and set-set laws for monadic lenses.

Reference operations

readRef :: Monad m => MLens m Unit a -> m aSource

writeRef :: Monad m => Ref m a -> a -> m ()Source

modRef :: Monad m => Ref m a -> (a -> a) -> m ()Source

Some impure 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.

Auxiliary definitions

logMLens :: Monad m => (a -> m ()) -> (a -> m ()) -> MLens m a aSource