haskus-utils-1.5: Haskus utility modules

Safe HaskellNone
LanguageHaskell2010

Haskus.Utils.MultiState

Description

State monad with multiple states (extensible)

Similar to the multistate package, with the following differences (as of 0.7.0.0): * don't pollute Data.HList.HList * use HArray instead of a HList, for fast indexing

Synopsis

Documentation

type MStateT (s :: [*]) m a = StateT (HArray s) m a Source #

Multi-state monad transformer

States are stacked in a heterogeneous array.

type MState (s :: [*]) a = MStateT s Identity a Source #

Multi-state

mSet :: (Monad m, HArrayIndexT a s) => a -> MStateT s m () Source #

Set a value in the state

mGet :: (Monad m, HArrayIndexT a s) => MStateT s m a Source #

Get a value in the state

mTryGet :: (Monad m, HArrayTryIndexT a s) => MStateT s m (Maybe a) Source #

Try to get a value in the state

mModify :: (Monad m, HArrayIndexT a s) => (a -> a) -> MStateT s m () Source #

Modify a value in the state

mModify' :: (Monad m, HArrayIndexT a s) => (a -> a) -> MStateT s m () Source #

Modify a value in the state (strict version)

mWith :: forall s a m b. Monad m => a -> MStateT (a ': s) m b -> MStateT s m b Source #

Execute an action with an extended state

runMState :: MState s a -> HArray s -> (a, HArray s) Source #

Run MState

evalMState :: MState s a -> HArray s -> a Source #

Evaluate MState

execMState :: MState s a -> HArray s -> HArray s Source #

Execute MState

liftMStateT :: Monad m => MStateT xs m x -> HArrayT m xs (x ': xs) Source #

Lift a multi-state into an HArray transformer

(>~:>) :: Monad m => HArrayT m xs ys -> MStateT ys m y -> HArrayT m xs (y ': ys) Source #

Compose MStateT

(>:>) :: Monad m => MStateT xs m x -> MStateT (x ': xs) m y -> HArrayT m xs (y ': (x ': xs)) Source #

Compose MStateT