ether-0.5.1.0: Monad transformers and classes

Safe HaskellNone
LanguageHaskell2010

Ether.State

Contents

Synopsis

MonadState class

class Monad m => MonadState tag s m | m tag -> s where Source #

Minimal complete definition

state | get, put

Methods

get :: m s Source #

Return the state from the internals of the monad.

put :: s -> m () Source #

Replace the state inside the monad.

state :: (s -> (a, s)) -> m a Source #

Embed a simple state action into the monad.

Instances

(MonadTrans t, Monad (t m), MonadState k tag s m) => MonadState k tag s (t m) Source # 

Methods

get :: m (t m) Source #

put :: t m -> m () Source #

state :: (t m -> (a, t m)) -> m a Source #

(MonadState k1 tag sOuter m, Reifies k z (ReifiedLens' sOuter sInner), (~) ((* -> *) -> * -> *) trans (IdentityT *)) => MonadState k1 tag sInner (TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m) Source # 

Methods

get :: m (TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m) Source #

put :: TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m -> m () Source #

state :: (TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m -> (a, TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m)) -> m a Source #

(Monad (trans m), MonadState k tag s (TaggedTrans * (Type -> Type) [a] effs trans m)) => MonadState k tag s (TaggedTrans * (Type -> Type) [a] ((:) a eff effs) trans m) Source # 

Methods

get :: m (TaggedTrans * (Type -> Type) [a] ((a ': eff) effs) trans m) Source #

put :: TaggedTrans * (Type -> Type) [a] ((a ': eff) effs) trans m -> m () Source #

state :: (TaggedTrans * (Type -> Type) [a] ((a ': eff) effs) trans m -> (a, TaggedTrans * (Type -> Type) [a] ((a ': eff) effs) trans m)) -> m a Source #

(MonadState k1 tNew s m, (~) ((* -> *) -> * -> *) trans (IdentityT *)) => MonadState k tOld s (TaggedTrans * (* -> *) * (TAG_REPLACE k1 k tOld tNew) trans m) Source # 

Methods

get :: m (TaggedTrans * (* -> *) * (TAG_REPLACE k1 k tOld tNew) trans m) Source #

put :: TaggedTrans * (* -> *) * (TAG_REPLACE k1 k tOld tNew) trans m -> m () Source #

state :: (TaggedTrans * (* -> *) * (TAG_REPLACE k1 k tOld tNew) trans m -> (a, TaggedTrans * (* -> *) * (TAG_REPLACE k1 k tOld tNew) trans m)) -> m a Source #

get :: MonadState tag s m => m s Source #

Return the state from the internals of the monad.

put :: MonadState tag s m => s -> m () Source #

Replace the state inside the monad.

state :: MonadState tag s m => (s -> (a, s)) -> m a Source #

Embed a simple state action into the monad.

modify :: forall tag s m. MonadState tag s m => (s -> s) -> m () Source #

Modifies the state inside a state monad.

gets :: forall tag s m a. MonadState tag s m => (s -> a) -> m a Source #

Gets specific component of the state, using a projection function supplied.

The State monad

type State tag r = StateT tag r Identity Source #

The parametrizable state monad.

Computations have access to a mutable state.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

runState :: forall tag s a. State tag s a -> s -> (a, s) Source #

Runs a State with the given initial state and returns both the final value and the final state.

evalState :: forall tag s a. State tag s a -> s -> a Source #

Runs a State with the given initial state and returns the final value, discarding the final state.

execState :: forall tag s a. State tag s a -> s -> s Source #

Runs a State with the given initial state and returns the final state, discarding the final value.

The StateT monad transformer

type StateT tag s = TaggedTrans (TAGGED STATE tag) (StateT s) Source #

The state monad transformer.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

stateT :: forall tag s m a. (s -> m (a, s)) -> StateT tag s m a Source #

Constructor for computations in the state monad transformer.

runStateT :: forall tag s m a. StateT tag s m a -> s -> m (a, s) Source #

Runs a StateT with the given initial state and returns both the final value and the final state.

evalStateT :: forall tag s m a. Monad m => StateT tag s m a -> s -> m a Source #

Runs a StateT with the given initial state and returns the final value, discarding the final state.

execStateT :: forall tag s m a. Monad m => StateT tag s m a -> s -> m s Source #

Runs a StateT with the given initial state and returns the final state, discarding the final value.

The State monad (lazy)

type LazyState tag r = LazyStateT tag r Identity Source #

The parametrizable state monad.

Computations have access to a mutable state.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

runLazyState :: forall tag s a. LazyState tag s a -> s -> (a, s) Source #

Runs a State with the given initial state and returns both the final value and the final state.

evalLazyState :: forall tag s a. LazyState tag s a -> s -> a Source #

Runs a State with the given initial state and returns the final value, discarding the final state.

execLazyState :: forall tag s a. LazyState tag s a -> s -> s Source #

Runs a State with the given initial state and returns the final state, discarding the final value.

The StateT monad transformer (lazy)

type LazyStateT tag s = TaggedTrans (TAGGED STATE tag) (StateT s) Source #

The state monad transformer.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

lazyStateT :: forall tag s m a. (s -> m (a, s)) -> LazyStateT tag s m a Source #

Constructor for computations in the state monad transformer.

runLazyStateT :: forall tag s m a. LazyStateT tag s m a -> s -> m (a, s) Source #

Runs a StateT with the given initial state and returns both the final value and the final state.

evalLazyStateT :: forall tag s m a. Monad m => LazyStateT tag s m a -> s -> m a Source #

Runs a StateT with the given initial state and returns the final value, discarding the final state.

execLazyStateT :: forall tag s m a. Monad m => LazyStateT tag s m a -> s -> m s Source #

Runs a StateT with the given initial state and returns the final state, discarding the final value.

The State monad (flattened)

runStates :: forall p a. States p a -> p -> (a, p) Source #

The StateT monad transformer (flattened)

runStatesT :: forall p m a. StatesT p m a -> p -> m (a, p) Source #

MonadState class (implicit)

get' :: forall s m. MonadState' s m => m s Source #

put' :: forall s m. MonadState' s m => s -> m () Source #

state' :: forall s m a. MonadState' s m => (s -> (a, s)) -> m a Source #

modify' :: forall s m. MonadState' s m => (s -> s) -> m () Source #

gets' :: forall s m a. MonadState' s m => (s -> a) -> m a Source #

The State monad (implicit)

type State' s = State s s Source #

runState' :: State' s a -> s -> (a, s) Source #

evalState' :: State' s a -> s -> a Source #

execState' :: State' s a -> s -> s Source #

The StateT monad transformer (implicit)

type StateT' s = StateT s s Source #

stateT' :: (s -> m (a, s)) -> StateT' s m a Source #

runStateT' :: StateT' s m a -> s -> m (a, s) Source #

evalStateT' :: Monad m => StateT' s m a -> s -> m a Source #

execStateT' :: Monad m => StateT' s m a -> s -> m s Source #

The State monad (lazy, implicit)

runLazyState' :: LazyState' s a -> s -> (a, s) Source #

The StateT monad transformer (lazy, implicit)

lazyStateT' :: (s -> m (a, s)) -> LazyStateT' s m a Source #

runLazyStateT' :: LazyStateT' s m a -> s -> m (a, s) Source #

evalLazyStateT' :: Monad m => LazyStateT' s m a -> s -> m a Source #

execLazyStateT' :: Monad m => LazyStateT' s m a -> s -> m s Source #

Zoom

zoom :: forall tag sOuter sInner m a. Lens' sOuter sInner -> (forall z. Reifies z (ReifiedLens' sOuter sInner) => ZoomT tag z m a) -> m a Source #

Zoom into a part of a state using a lens.

Internal labels

data TAGGED e t Source #

data STATE Source #

Encode type-level information for StateT.

Instances

Handle * * STATE s (StateT s) Source # 

Methods

handling :: Monad m => (HandleConstraint STATE s (StateT s) p trans m -> r) -> r Source #

Handle * * STATE s (StateT s) Source # 

Methods

handling :: Monad m => (HandleConstraint STATE s (StateT s) p trans m -> r) -> r Source #

type HandleSuper kp * STATE s trans Source # 
type HandleSuper kp * STATE s trans = ()
type HandleConstraint * * STATE s trans m Source # 
type HandleConstraint * * STATE s trans m = MonadState s (trans m)

type family STATES (ts :: HList xs) :: [Type] where ... Source #

Equations

STATES HNil = '[] 
STATES (HCons t ts) = TAGGED STATE t ': STATES ts 

data ZOOM t z Source #

Encode type-level information for zoom.

Instances

(MonadState k1 tag sOuter m, Reifies k z (ReifiedLens' sOuter sInner), (~) ((* -> *) -> * -> *) trans (IdentityT *)) => MonadState k1 tag sInner (TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m) Source # 

Methods

get :: m (TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m) Source #

put :: TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m -> m () Source #

state :: (TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m -> (a, TaggedTrans * (* -> *) * (ZOOM k k1 tag z) trans m)) -> m a Source #