data-effects-0.4.2.0: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2023-2025 Sayo contributors
LicenseMPL-2.0 (see the file LICENSE)
Maintainerymdfield@outlook.jp
Safe HaskellNone
LanguageGHC2021

Data.Effect.State

Description

Effects for holding mutable state values in the context.

Synopsis

Documentation

get :: forall s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, State s :> es) => a s Source #

put :: forall s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, State s :> es) => s -> a () Source #

gets :: forall s (es :: [Effect]) a (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (State s :> es, Functor (Eff ff es), Free c ff) => (s -> a) -> Eff ff es a Source #

Retrieves the current state value from the context and returns the value transformed based on the given function.

modify :: forall s (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (State s :> es, Monad (Eff ff es), Free c ff) => (s -> s) -> Eff ff es () Source #

Modifies the current state value in the context based on the given function.

runStateIORef :: forall s (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) a (c :: (Type -> Type) -> Constraint). (Emb IO :> es, Monad (Eff ff es), Free c ff) => s -> Eff ff (State s ': es) a -> Eff ff es (s, a) Source #

Interpret the State effect based on an IO-fused semantics using IORef.

evalStateIORef :: forall s (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) a (c :: (Type -> Type) -> Constraint). (Emb IO :> es, Monad (Eff ff es), Free c ff) => s -> Eff ff (State s ': es) a -> Eff ff es a Source #

Interpret the State effect based on an IO-fused semantics using IORef. Do not include the final state in the return value.

execStateIORef :: forall s (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) a (c :: (Type -> Type) -> Constraint). (Emb IO :> es, Monad (Eff ff es), Free c ff) => s -> Eff ff (State s ': es) a -> Eff ff es s Source #

localToState :: forall r (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) a (c :: (Type -> Type) -> Constraint). (In (State r) es, Monad (Eff ff es), Free c ff) => Eff ff (Local r ': es) a -> Eff ff es a Source #

get'_ :: forall s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, In (State s) es) => a s Source #

put'_ :: forall s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, In (State s) es) => s -> a () Source #

askToGet :: forall r (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) a (c :: (Type -> Type) -> Constraint). (In (State r) es, Free c ff) => Eff ff (Ask r ': es) a -> Eff ff es a Source #

get' :: forall {k} (key :: k) s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Has key (State s) es) => a s Source #

get'' :: forall {k} (tag :: k) s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Tagged tag (State s) :> es) => a s Source #

put' :: forall {k} (key :: k) s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Has key (State s) es) => s -> a () Source #

put'' :: forall {k} (tag :: k) s a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Tagged tag (State s) :> es) => s -> a () Source #

data State s (a :: Type -> Type) b where #

An effect for holding mutable state values in the context.

Constructors

Get :: forall s (a :: Type -> Type). State s a s

Retrieves the current state value from the context.

Put :: forall s (a :: Type -> Type). s -> State s a ()

Overwrites the state value in the context.

Instances

Instances details
FirstOrder (State s) 
Instance details

Defined in Data.Effect

PolyHFunctor (State s) 
Instance details

Defined in Data.Effect

HFunctor (State s) 
Instance details

Defined in Data.Effect

Methods

hfmap :: (forall x. f x -> g x) -> State s f a -> State s g a #

type FormOf (State s) 
Instance details

Defined in Data.Effect

type FormOf (State s) = 'Polynomial
type LabelOf (State s) 
Instance details

Defined in Data.Effect

type OrderOf (State s) 
Instance details

Defined in Data.Effect