Module Control.monad.State

The strict State Monad

Imports

Table of Content

Definitions

data State s a

State s a is an abstract data type that resembles a stateful computation with State s and result a, i.e. functions of type s -> (a, s) where the State is immutable.

Constructors

private State {fun ∷ s → (a, s)}

Member Functions

funState 𝖇 𝖆 → 𝖇 → (𝖆, 𝖇)

access field fun

getState 𝖆 𝖆

return the state from the internals of the monad

modify ∷ (𝖆→𝖆) → State 𝖆 ()

modify the State

put ∷ 𝖆 → State 𝖆 ()

replace the State inside the monad

runState 𝖆 𝖇 → 𝖆 → (𝖇, 𝖆)

run a stateful computation

state ∷ (𝖇→(𝖆, 𝖇)) → State 𝖇 𝖆

make an instance of State using an appropriate function, for example

 state random   
runStateState 𝖆 𝖇 → 𝖆 → (𝖇, 𝖆)

Alias for State.run

evalStateState 𝖆 𝖇 → 𝖆 → 𝖇
execStateState 𝖇 𝖆 → 𝖇 → 𝖇
runStateTMonad m ⇒ StateT s m v → s → m (v, s)
evalStateTMonad m ⇒ StateT s m v → s → m v
execStateTMonad m ⇒ StateT s m v → s → m s
data StateT s m a
 StateT s m a

A stateful computation that transforms an inner Monad m

Constructors

private StateT {run ∷ s → m (a, s)}

Member Functions

getApplicative 𝖆 ⇒ StateT 𝖇 𝖆 𝖇
modifyApplicative 𝖆 ⇒ (𝖇→𝖇) → StateT 𝖇 𝖆 ()
putApplicative 𝖇 ⇒ 𝖆 → StateT 𝖆 𝖇 ()
runStateT 𝖈 𝖆 𝖇 → 𝖈 → 𝖆 (𝖇, 𝖈)

access field run

promoteApplicative 𝖆 ⇒ State 𝖈 𝖇 → StateT 𝖈 𝖆 𝖇

Instances

instance MonadAlt m ⇒ MonadAlt (StateT s m)

Member Functions

<+>MonadAlt 𝖇 ⇒ StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖈
infixr  13
<|>MonadAlt 𝖇 ⇒ StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖈
infixl  3
pzeroMonadAlt 𝖇 ⇒ StateT 𝖆 𝖇 𝖈
instance MonadIO m ⇒ MonadIO (StateT s m)

Member Functions

liftIOMonadIO 𝖇 ⇒ IO 𝖈 → StateT 𝖆 𝖇 𝖈
instance MonadPlus m ⇒ MonadPlus (StateT s m)

Member Functions

mplusMonadPlus 𝖇 ⇒ StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖈
infixr  13
mzeroMonadPlus 𝖇 ⇒ StateT 𝖆 𝖇 𝖈
instance MonadTrans (StateT s)

Member Functions

liftMonad 𝖈 ⇒ 𝖈 𝖇 → StateT 𝖆 𝖈 𝖇
instance Monad (State s)

Member Functions

*>State 𝖆 𝖇 → State 𝖆 𝖈 → State 𝖆 𝖈
infixl  4

inherited from Applicative.*>

<*State 𝖆 𝖇 → State 𝖆 𝖈 → State 𝖆 𝖇
infixl  4

inherited from Applicative.<*

<*>State 𝖆 (𝖇→𝖈) → State 𝖆 𝖇 → State 𝖆 𝖈
infixl  4

inherited from Monad.<*>

>>State 𝖆 𝖇State 𝖆 𝖈State 𝖆 𝖈
infixl  3
>>=State 𝖆 𝖇 → (𝖇 → State 𝖆 𝖈) → State 𝖆 𝖈
infixl  3

monadic bind for the State monad

fmap ∷ (𝖇 → 𝖈) → State 𝖆 𝖇State 𝖆 𝖈
infixl  4

inherited from Monad.fmap

joinState 𝖆 (State 𝖆 𝖇)State 𝖆 𝖇

inherited from Monad.join

pure𝖇State 𝖆 𝖇

lift a value to the State monad

instance Monad m ⇒ Monad (StateT s m)

Member Functions

*>Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉 → StateT 𝖆 𝖇 𝖉
infixl  4

inherited from Applicative.*>

<*Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉 → StateT 𝖆 𝖇 𝖈
infixl  4

inherited from Applicative.<*

<*>Monad 𝖇 ⇒ StateT 𝖆 𝖇 (𝖈→𝖉) → StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉
infixl  4

inherited from Monad.<*>

>>Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖉 → StateT 𝖆 𝖇 𝖉
infixl  3
>>=Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → (𝖈 → StateT 𝖆 𝖇 𝖉) → StateT 𝖆 𝖇 𝖉
infixl  3
fmapMonad 𝖇 ⇒ (𝖈 → 𝖉) → StateT 𝖆 𝖇 𝖈StateT 𝖆 𝖇 𝖉
infixl  4

inherited from Monad.fmap

joinMonad 𝖇 ⇒ StateT 𝖆 𝖇 (StateT 𝖆 𝖇 𝖈)StateT 𝖆 𝖇 𝖈

inherited from Monad.join

pureMonad 𝖇 ⇒ 𝖈StateT 𝖆 𝖇 𝖈

Functions and Values by Type

(𝖆→𝖆) → State 𝖆 ()

State.modify

𝖆 → State 𝖆 ()

State.put

𝖆 → Bool

State.has$fun, StateT.has$run

State 𝖆 𝖆

State.get

(s → (a, s)) → State s a

State.State

State 𝖆 (State 𝖆 𝖇) → State 𝖆 𝖇

Monad_State.join

State 𝖆 𝖇 → 𝖆 → (𝖇, 𝖆)

State.run

State 𝖆 𝖇 → 𝖆 → 𝖇

evalState

State 𝖇 𝖆 → 𝖇 → (𝖆, 𝖇)

State.fun

State 𝖇 𝖆 → 𝖇 → 𝖇

execState

(𝖇→(𝖆, 𝖇)) → State 𝖇 𝖆

state

𝖇 → State 𝖆 𝖇

Monad_State.pure

Applicative 𝖆 ⇒ (𝖇→𝖇) → StateT 𝖇 𝖆 ()

StateT.modify

Applicative 𝖇 ⇒ 𝖆 → StateT 𝖆 𝖇 ()

StateT.put

Applicative 𝖆 ⇒ StateT 𝖇 𝖆 𝖇

StateT.get

(s → m (a, s)) → StateT s m a

StateT.StateT

(𝖇 → 𝖈) → State 𝖆 𝖇 → State 𝖆 𝖈

Monad_State.fmap

StateT 𝖈 𝖆 𝖇 → 𝖈 → 𝖆 (𝖇, 𝖈)

StateT.run

State 𝖆 (𝖇→𝖈) → State 𝖆 𝖇 → State 𝖆 𝖈

Monad_State.<*>

State 𝖆 𝖇 → (𝖇 → State 𝖆 𝖈) → State 𝖆 𝖈

Monad_State.>>=

State 𝖆 𝖇 → State 𝖆 𝖈 → State 𝖆 𝖇

Monad_State.<*

State 𝖆 𝖇 → State 𝖆 𝖈 → State 𝖆 𝖈

Monad_State.*>, Monad_State.>>

MonadIO 𝖇 ⇒ IO 𝖈 → StateT 𝖆 𝖇 𝖈

MonadIO_StateT.liftIO

Applicative 𝖆 ⇒ State 𝖈 𝖇 → StateT 𝖈 𝖆 𝖇

promote

Monad m ⇒ StateT s m v → s → m (v, s)

runStateT

Monad m ⇒ StateT s m v → s → m s

execStateT

Monad m ⇒ StateT s m v → s → m v

evalStateT

Monad 𝖇 ⇒ StateT 𝖆 𝖇 (StateT 𝖆 𝖇 𝖈) → StateT 𝖆 𝖇 𝖈

Monad_StateT.join

Monad 𝖇 ⇒ 𝖈 → StateT 𝖆 𝖇 𝖈

Monad_StateT.pure

Monad 𝖈 ⇒ 𝖈 𝖇 → StateT 𝖆 𝖈 𝖇

MonadTrans_StateT.lift

MonadAlt 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖈

MonadAlt_StateT.<+>, MonadAlt_StateT.<|>

MonadPlus 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖈

MonadPlus_StateT.mplus

MonadAlt 𝖇 ⇒ StateT 𝖆 𝖇 𝖈

MonadAlt_StateT.pzero

MonadPlus 𝖇 ⇒ StateT 𝖆 𝖇 𝖈

MonadPlus_StateT.mzero

State 𝖆 𝖇 → (-> 𝖆 (𝖇, 𝖆)→𝖉→(𝖈, 𝖉)) → State 𝖉 𝖈

State.chg$fun

State 𝖆 𝖇 → (𝖉→(𝖈, 𝖉)) → State 𝖉 𝖈

State.upd$fun

Monad 𝖇 ⇒ (𝖈 → 𝖉) → StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉

Monad_StateT.fmap

Monad 𝖇 ⇒ StateT 𝖆 𝖇 (𝖈→𝖉) → StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉

Monad_StateT.<*>

Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → (𝖈 → StateT 𝖆 𝖇 𝖉) → StateT 𝖆 𝖇 𝖉

Monad_StateT.>>=

Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉 → StateT 𝖆 𝖇 𝖈

Monad_StateT.<*

Monad 𝖇 ⇒ StateT 𝖆 𝖇 𝖈 → StateT 𝖆 𝖇 𝖉 → StateT 𝖆 𝖇 𝖉

Monad_StateT.*>, Monad_StateT.>>

StateT 𝖆 𝖇 𝖈 → (-> 𝖆 (𝖇 (𝖈, 𝖆))→𝖋→𝖉 (𝖊, 𝖋)) → StateT 𝖋 𝖉 𝖊

StateT.chg$run

StateT 𝖆 𝖇 𝖈 → (𝖋→𝖉 (𝖊, 𝖋)) → StateT 𝖋 𝖉 𝖊

StateT.upd$run

Valid HTML 4.01 Strict