Safe Haskell | None |
---|---|
Language | Haskell98 |
Support for the LB (LambdaBot) monad
- class MonadLB m => MonadLBState m where
- readMS :: MonadLBState m => m (LBState m)
- writeMS :: MonadLBState m => LBState m -> m ()
- modifyMS :: MonadLBState m => (LBState m -> LBState m) -> m ()
- data GlobalPrivate g p
- mkGlobalPrivate :: Int -> g -> GlobalPrivate g p
- withPS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => Nick -> (Maybe p -> (Maybe p -> LB ()) -> LB a) -> m a
- readPS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => Nick -> m (Maybe p)
- writePS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => Nick -> Maybe p -> m ()
- withGS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => (g -> (g -> m ()) -> m ()) -> m ()
- readGS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => m g
- writeGS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => g -> m ()
- readGlobalState :: Module st -> String -> LB (Maybe st)
- writeGlobalState :: ModuleT st LB ()
Functions to access the module's state
class MonadLB m => MonadLBState m where Source
withMS :: (LBState m -> (LBState m -> m ()) -> m a) -> m a Source
Update the module's private state.
This is the preferred way of changing the state. The state will be locked
until the body returns. The function is exception-safe, i.e. even if
an error occurs or the thread is killed (e.g. because it deadlocked and
therefore exceeded its time limit), the state from the last write operation
will be restored. If the writer escapes, calling it will have no observable
effect.
withMS
is not composable, in the sense that a readMS from within the body
will cause a dead-lock. However, all other possibilies to access the state
that came to my mind had even more serious deficiencies such as being prone
to race conditions or semantic obscurities.
MonadLBState m => MonadLBState (Cmd m) Source | |
MonadLB m => MonadLBState (ModuleT st m) Source |
readMS :: MonadLBState m => m (LBState m) Source
Read the module's private state.
writeMS :: MonadLBState m => LBState m -> m () Source
Write the module's private state. Try to use withMS instead.
modifyMS :: MonadLBState m => (LBState m -> LBState m) -> m () Source
Modify the module's private state.
Utility functions for modules that need state for each target.
data GlobalPrivate g p Source
This datatype allows modules to conviently maintain both global (i.e. for all clients they're interacting with) and private state. It is implemented on top of readMS/withMS.
This simple implementation is linear in the number of private states used.
mkGlobalPrivate :: Int -> g -> GlobalPrivate g p Source
Creates a GlobalPrivate
given the value of the global state. No private
state for clients will be created.
:: (MonadLBState m, LBState m ~ GlobalPrivate g p) | |
=> Nick | The target |
-> (Maybe p -> (Maybe p -> LB ()) -> LB a) |
|
-> m a |
Writes private state. For now, it locks everything.
readPS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => Nick -> m (Maybe p) Source
Reads private state.
writePS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => Nick -> Maybe p -> m () Source
withGS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => (g -> (g -> m ()) -> m ()) -> m () Source
Writes global state. Locks everything
readGS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => m g Source
Reads global state.
writeGS :: (MonadLBState m, LBState m ~ GlobalPrivate g p) => g -> m () Source
Handling global state
writeGlobalState :: ModuleT st LB () Source
Peristence: write the global state out