fused-effects-0.3.1.0: A fast, flexible, fused effect system.

Safe HaskellNone
LanguageHaskell2010

Control.Effect.State.Lazy

Synopsis

Documentation

data State s (m :: * -> *) k Source #

Constructors

Get (s -> k) 
Put s k 
Instances
Effect (State s) Source # 
Instance details

Defined in Control.Effect.State.Internal

Methods

handle :: Functor f => f () -> (forall x. f (m x) -> n (f x)) -> State s m (m a) -> State s n (n (f a)) Source #

HFunctor (State s) Source # 
Instance details

Defined in Control.Effect.State.Internal

Methods

fmap' :: (a -> b) -> State s m a -> State s m b Source #

hmap :: (forall x. m x -> n x) -> State s m a -> State s n a Source #

Functor (State s m) Source # 
Instance details

Defined in Control.Effect.State.Internal

Methods

fmap :: (a -> b) -> State s m a -> State s m b #

(<$) :: a -> State s m b -> State s m a #

(Carrier sig m, Effect sig) => Carrier (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Strict

Methods

eff :: (State s :+: sig) (StateC s m) (StateC s m a) -> StateC s m a Source #

ret :: a -> StateC s m a Source #

(Carrier sig m, Effect sig) => Carrier (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

eff :: (State s :+: sig) (StateC s m) (StateC s m a) -> StateC s m a Source #

ret :: a -> StateC s m a Source #

get :: (Member (State s) sig, Carrier sig m) => m s Source #

Get the current state value.

snd (run (runState a get)) == a

gets :: (Member (State s) sig, Carrier sig m) => (s -> a) -> m a Source #

Project a function out of the current state value.

snd (run (runState a (gets (applyFun f)))) == applyFun f a

put :: (Member (State s) sig, Carrier sig m) => s -> m () Source #

Replace the state value with a new value.

fst (run (runState a (put b))) == b
snd (run (runState a (get <* put b))) == a
snd (run (runState a (put b *> get))) == b

modify :: (Member (State s) sig, Carrier sig m) => (s -> s) -> m () Source #

Replace the state value with the result of applying a function to the current state value. This is strict in the new state.

fst (run (runState a (modify (+1)))) == (1 + a :: Integer)

modifyLazy :: (Member (State s) sig, Carrier sig m) => (s -> s) -> m () Source #

Replace the state value with the result of applying a function to the current state value. This is lazy in the new state; injudicious use of this function may lead to space leaks.

newtype StateC s m a Source #

Constructors

StateC 

Fields

Instances
MonadTrans (StateC s) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

lift :: Monad m => m a -> StateC s m a #

Monad m => Monad (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

(>>=) :: StateC s m a -> (a -> StateC s m b) -> StateC s m b #

(>>) :: StateC s m a -> StateC s m b -> StateC s m b #

return :: a -> StateC s m a #

fail :: String -> StateC s m a #

Functor m => Functor (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

fmap :: (a -> b) -> StateC s m a -> StateC s m b #

(<$) :: a -> StateC s m b -> StateC s m a #

MonadFail m => MonadFail (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

fail :: String -> StateC s m a #

(Functor m, Monad m) => Applicative (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

pure :: a -> StateC s m a #

(<*>) :: StateC s m (a -> b) -> StateC s m a -> StateC s m b #

liftA2 :: (a -> b -> c) -> StateC s m a -> StateC s m b -> StateC s m c #

(*>) :: StateC s m a -> StateC s m b -> StateC s m b #

(<*) :: StateC s m a -> StateC s m b -> StateC s m a #

MonadIO m => MonadIO (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

liftIO :: IO a -> StateC s m a #

(Alternative m, Monad m) => Alternative (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

empty :: StateC s m a #

(<|>) :: StateC s m a -> StateC s m a -> StateC s m a #

some :: StateC s m a -> StateC s m [a] #

many :: StateC s m a -> StateC s m [a] #

(Alternative m, Monad m) => MonadPlus (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

mzero :: StateC s m a #

mplus :: StateC s m a -> StateC s m a -> StateC s m a #

(Carrier sig m, Effect sig) => Carrier (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Effect.State.Lazy

Methods

eff :: (State s :+: sig) (StateC s m) (StateC s m a) -> StateC s m a Source #

ret :: a -> StateC s m a Source #

runState :: s -> StateC s m a -> m (s, a) Source #

Run a lazy State effect, yielding the result value and the final state. More programs terminate with lazy state than strict state, but injudicious use of lazy state may lead to thunk buildup.

run (runState a (pure b)) == (a, b)
take 5 . snd . run $ runState () (traverse pure [1..]) == [1,2,3,4,5]

evalState :: forall s m a. Functor m => s -> StateC s m a -> m a Source #

Run a lazy State effect, yielding the result value and discarding the final state.

run (evalState a (pure b)) == b

execState :: forall s m a. Functor m => s -> StateC s m a -> m s Source #

Run a lazy State effect, yielding the final state and discarding the return value.

run (execState a (pure b)) == a