Arrow Libraries (arrows package)ParentContentsIndex
Control.Arrow.Transformer.State
Portability non-portable (multi-parameter type classes)
Stability experimental
Maintainer ross@soi.city.ac.uk
Description
An arrow transformer that adds a modifiable state, based of section 9 of Generalising Monads to Arrows, by John Hughes, Science of Computer Programming 37:67-111, May 2000.
Synopsis
data StateArrow s a b c
runState :: Arrow a => StateArrow s a e b -> a (e, s) (b, s)
class (ArrowState s a, Arrow a') => ArrowAddState s a a' | a -> a' where
liftState :: a' e b -> a e b
elimState :: a e b -> a' (e, s) (b, s)
module Control.Arrow.Operations
module Control.Arrow.Transformer
Documentation
data StateArrow s a b c
An arrow type that augments an existing arrow with a modifiable state. The ArrowState class contains the operations on this state.
Instances
Arrow a => Arrow (StateArrow s a)
ArrowAddError ex a a' => ArrowAddError ex (StateArrow s a) (StateArrow s a')
ArrowAddError ex a a' => ArrowAddError ex (StateArrow s a) (StateArrow s a')
ArrowAddReader r a a' => ArrowAddReader r (StateArrow s a) (StateArrow s a')
ArrowAddReader r a a' => ArrowAddReader r (StateArrow s a) (StateArrow s a')
Arrow a => ArrowAddState s (StateArrow s a) a
ArrowAddWriter w a a' => ArrowAddWriter w (StateArrow s a) (StateArrow s a')
ArrowAddWriter w a a' => ArrowAddWriter w (StateArrow s a) (StateArrow s a')
ArrowApply a => ArrowApply (StateArrow s a)
ArrowChoice a => ArrowChoice (StateArrow s a)
ArrowCircuit a => ArrowCircuit (StateArrow s a)
ArrowError ex a => ArrowError ex (StateArrow s a)
ArrowLoop a => ArrowLoop (StateArrow s a)
ArrowPlus a => ArrowPlus (StateArrow s a)
ArrowReader r a => ArrowReader r (StateArrow s a)
Arrow a => ArrowState s (StateArrow s a)
Arrow a => ArrowTransformer (StateArrow s) a
ArrowWriter w a => ArrowWriter w (StateArrow s a)
ArrowZero a => ArrowZero (StateArrow s a)
runState :: Arrow a => StateArrow s a e b -> a (e, s) (b, s)

Encapsulation of a state-using computation, exposing the initial and final states.

Typical usage in arrow notation:

	proc p -> do
		...
		(result, final_state) <- (|runState cmd|) init_state
class (ArrowState s a, Arrow a') => ArrowAddState s a a' | a -> a' where

Adding a StateArrow to an arrow type, but not necessarily as the outer arrow transformer.

Typically a composite arrow type is built by applying a series of arrow transformer to a base arrow (usually either a function arrow or a Kleisli arrow. One can add a transformer to the top of this stack using the lift method of the ArrowTransformer class, or remove a state transformer from the top of the stack using the runState encapsulation operator. The methods of this class add and remove state transformers anywhere in the stack. In the instance

	instance Arrow a => ArrowAddState s (ArrowState s a) a

they are equivalent to lift and runState respectively. Instances are lifted through other transformers with

	instance ArrowAddState s a a' =>
		ArrowAddState s (FooArrow a) (FooArrow a')
Methods
liftState :: a' e b -> a e b

Lift a computation from an arrow to one with an added state.

Typical usage in arrow notation:

	proc p -> ...
		(|liftState cmd|)
elimState :: a e b -> a' (e, s) (b, s)

Elimination of a state transformer from a computation, exposing the initial and final states.

Typical usage in arrow notation:

	proc p -> do
		...
		(result, final_state) <- (|elimState cmd|) init_state
Instances
ArrowAddState r a a' => ArrowAddState r (Automaton a) (Automaton a')
(ArrowAddState s a a', ArrowChoice a, ArrowChoice a') => ArrowAddState s (ErrorArrow ex a) (ErrorArrow ex a')
ArrowAddState s a a' => ArrowAddState s (ReaderArrow r a) (ReaderArrow r a')
Arrow a => ArrowAddState s (StateArrow s a) a
(ArrowAddState s a a', Sequence f) => ArrowAddState s (StaticArrow f a) (StaticArrow f a')
(ArrowAddState s a a', Monoid w) => ArrowAddState s (WriterArrow w a) (WriterArrow w a')
module Control.Arrow.Operations
module Control.Arrow.Transformer
Produced by Haddock version 0.5