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

Control.Effect.State

Contents

Description

An effect that adds a mutable, updatable state value to a given computation.

Not all computations require a full-fledged state effect: read-only state is better served by Reader, and append-only state without reads is better served by Writer.

Predefined carriers:

Since: 0.1.0.0

Synopsis

# State effect

data State s m k Source #

Since: 0.1.0.0

Constructors

 Get (s -> m k) Put s (m k)
Instances
 Effect (State s) Source # Instance detailsDefined in Control.Effect.State.Internal Methodsthread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> State s m a -> State s n (ctx a) Source # Source # Instance detailsDefined in Control.Effect.State.Internal Methodshmap :: Functor m => (forall x. m x -> n x) -> State s m a -> State s n a Source # Generic1 (State s m :: Type -> Type) Source # Instance detailsDefined in Control.Effect.State.Internal Associated Typestype Rep1 (State s m) :: k -> Type # Methodsfrom1 :: State s m a -> Rep1 (State s m) a #to1 :: Rep1 (State s m) a -> State s m a # Functor m => Functor (State s m) Source # Instance detailsDefined in Control.Effect.State.Internal Methodsfmap :: (a -> b) -> State s m a -> State s m b #(<$) :: a -> State s m b -> State s m a # (Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateT s m) Source # Instance detailsDefined in Control.Algebra Methodsalg :: (State s :+: sig) (StateT s m) a -> StateT s m a Source # (Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateT s m) Source # Instance detailsDefined in Control.Algebra Methodsalg :: (State s :+: sig) (StateT s m) a -> StateT s m a Source # (Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateC s m) Source # Instance detailsDefined in Control.Carrier.State.Strict Methodsalg :: (State s :+: sig) (StateC s m) a -> StateC s m a Source # (Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateC s m) Source # Instance detailsDefined in Control.Carrier.State.Lazy Methodsalg :: (State s :+: sig) (StateC s m) a -> StateC s m a Source # (Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # Instance detailsDefined in Control.Algebra Methodsalg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source # (Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # Instance detailsDefined in Control.Algebra Methodsalg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source # type Rep1 (State s m :: Type -> Type) Source # Instance detailsDefined in Control.Effect.State.Internal type Rep1 (State s m :: Type -> Type) = D1 (MetaData "State" "Control.Effect.State.Internal" "fused-effects-1.0.0.0-inplace" False) (C1 (MetaCons "Get" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (((->) s :: Type -> Type) :.: Rec1 m)) :+: C1 (MetaCons "Put" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 s) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec1 m))) get :: Has (State s) sig m => m s Source # Get the current state value. runState a (get >>= k) = runState a (k a)  Since: 0.1.0.0 gets :: Has (State s) sig m => (s -> a) -> m a Source # Project a function out of the current state value. gets f = fmap f get  Since: 0.1.0.0 put :: Has (State s) sig m => s -> m () Source # Replace the state value with a new value. runState a (put b >> m) = runState b m  Since: 0.1.0.0 modify :: Has (State s) 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. modify f = get >>= (put . f $!)


Since: 0.1.0.0

modifyLazy :: Has (State s) 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.

modifyLazy f = get >>= put . f


Since: 0.3.0.0

# Re-exports

class (HFunctor sig, Monad m) => Algebra sig m | m -> sig Source #

The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg method.

Since: 1.0.0.0

Minimal complete definition

alg

Instances

type Has eff sig m = (Members eff sig, Algebra sig m) Source #

m is a carrier for sig containing eff.

Note that if eff is a sum, it will be decomposed into multiple Member constraints. While this technically allows one to combine multiple unrelated effects into a single Has constraint, doing so has two significant drawbacks:

1. Due to a problem with recursive type families, this can lead to significantly slower compiles.
2. It defeats ghc’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.

run :: Identity a -> a Source #

Run an action exhausted of effects to produce its final result value.

Since: 1.0.0.0