lambdabot-core-5.1: Lambdabot core functionality

Safe HaskellNone




Support for the LB (LambdaBot) monad


Functions to access the module's state

class MonadLB m => MonadLBState m where Source

Associated Types

type LBState m 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.

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.

withPS Source


:: (MonadLBState m, LBState m ~ GlobalPrivate g p) 
=> Nick

The target

-> (Maybe p -> (Maybe p -> LB ()) -> LB a)

Just x writes x in the user's private state, Nothing removes it.

-> 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

readGlobalState :: Module st -> String -> LB (Maybe st) Source

Read it in

writeGlobalState :: ModuleT st LB () Source

Peristence: write the global state out