arrows-0.4.4.2: Arrow classes and transformers

Copyright | (c) Ross Paterson 2003
License | BSD-style (see the LICENSE file in the distribution)
Maintainer | R.Paterson@city.ac.uk
Stability | experimental
Portability | non-portable (multi-parameter type classes)
Safe Haskell | Safe
Language | Haskell98

Control.Arrow.Transformer.State

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

- newtype StateArrow s a b c = StateArrow (a (b, s) (c, s))
- 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)

# Documentation

newtype StateArrow s a b c Source #

An arrow type that augments an existing arrow with a modifiable state. The `ArrowState` class contains the operations on this state.

Constructors

StateArrow (a (b, s) (c, s)) |

Instances

ArrowError ex a => ArrowError ex (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods raise :: StateArrow s a ex b Source # handle :: StateArrow s a e b -> StateArrow s a (e, ex) b -> StateArrow s a e b Source # tryInUnless :: StateArrow s a e b -> StateArrow s a (e, b) c -> StateArrow s a (e, ex) c -> StateArrow s a e c Source # newError :: StateArrow s a e b -> StateArrow s a e (Either ex b) Source #
ArrowWriter w a => ArrowWriter w (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods write :: StateArrow s a w () Source # newWriter :: StateArrow s a e b -> StateArrow s a e (b, w) Source #
Arrow a => ArrowState s (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods fetch :: StateArrow s a e s Source # store :: StateArrow s a s () Source #
ArrowReader r a => ArrowReader r (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods readState :: StateArrow s a b r Source # newReader :: StateArrow s a e b -> StateArrow s a (e, r) b Source #
Arrow a => ArrowAddState s (StateArrow s a) a Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods liftState :: a e b -> StateArrow s a e b Source # elimState :: StateArrow s a e b -> a (e, s) (b, s) Source #
ArrowAddError ex a a' => ArrowAddError ex (StateArrow s a) (StateArrow s a') Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods liftError :: StateArrow s a' e b -> StateArrow s a e b Source # elimError :: StateArrow s a e b -> StateArrow s a' (e, ex) b -> StateArrow s a' e b Source #
ArrowAddWriter w a a' => ArrowAddWriter w (StateArrow s a) (StateArrow s a') Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods liftWriter :: StateArrow s a' e b -> StateArrow s a e b Source # elimWriter :: StateArrow s a e b -> StateArrow s a' e (b, w) Source #
ArrowAddReader r a a' => ArrowAddReader r (StateArrow s a) (StateArrow s a') Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods liftReader :: StateArrow s a' e b -> StateArrow s a e b Source # elimReader :: StateArrow s a e b -> StateArrow s a' (e, r) b Source #
Arrow a => ArrowTransformer (StateArrow s) a Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods lift :: a b c -> StateArrow s a b c Source #
Category a => Category (StateArrow s a :: Type -> Type -> Type) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods id :: StateArrow s a a0 a0 Source # (.) :: StateArrow s a b c -> StateArrow s a a0 b -> StateArrow s a a0 c Source #
Arrow a => Arrow (StateArrow s a) Source # |

Instance details

Defined in Control.Arrow.Transformer.State

Methods

arr :: (b -> c) -> StateArrow s a b c Source #

first :: StateArrow s a b c -> StateArrow s a (b, d) (c, d) Source #

second :: StateArrow s a b c -> StateArrow s a (d, b) (d, c) Source #

(***) :: StateArrow s a b c -> StateArrow s a b' c' -> StateArrow s a (b, b') (c, c') Source #

(&&&) :: StateArrow s a b c -> StateArrow s a b c' -> StateArrow s a b (c, c') Source #

ArrowZero a => ArrowZero (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods zeroArrow :: StateArrow s a b c Source #
ArrowPlus a => ArrowPlus (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods (<+>) :: StateArrow s a b c -> StateArrow s a b c -> StateArrow s a b c Source #
ArrowChoice a => ArrowChoice (StateArrow s a) Source # |

Instance details

Defined in Control.Arrow.Transformer.State

Methods

left :: StateArrow s a b c -> StateArrow s a (Either b d) (Either c d) Source #

right :: StateArrow s a b c -> StateArrow s a (Either d b) (Either d c) Source #

(+++) :: StateArrow s a b c -> StateArrow s a b' c' -> StateArrow s a (Either b b') (Either c c') Source #

(|||) :: StateArrow s a b d -> StateArrow s a c d -> StateArrow s a (Either b c) d Source #

ArrowApply a => ArrowApply (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods app :: StateArrow s a (StateArrow s a b c, b) c Source #
ArrowLoop a => ArrowLoop (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods loop :: StateArrow s a (b, d) (c, d) -> StateArrow s a b c Source #
ArrowCircuit a => ArrowCircuit (StateArrow s a) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods delay :: b -> StateArrow s a b b Source #
Arrow a => Functor (StateArrow s a b) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods fmap :: (a0 -> b0) -> StateArrow s a b a0 -> StateArrow s a b b0 Source # (<$) :: a0 -> StateArrow s a b b0 -> StateArrow s a b a0 Source #
Arrow a => Applicative (StateArrow s a b) Source # |

Instance details

Defined in Control.Arrow.Transformer.State

Methods

pure :: a0 -> StateArrow s a b a0 Source #

(<*>) :: StateArrow s a b (a0 -> b0) -> StateArrow s a b a0 -> StateArrow s a b b0 Source #

liftA2 :: (a0 -> b0 -> c) -> StateArrow s a b a0 -> StateArrow s a b b0 -> StateArrow s a b c Source #

(*>) :: StateArrow s a b a0 -> StateArrow s a b b0 -> StateArrow s a b b0 Source #

(<*) :: StateArrow s a b a0 -> StateArrow s a b b0 -> StateArrow s a b a0 Source #

ArrowPlus a => Alternative (StateArrow s a b) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods empty :: StateArrow s a b a0 Source # (<|>) :: StateArrow s a b a0 -> StateArrow s a b a0 -> StateArrow s a b a0 Source # some :: StateArrow s a b a0 -> StateArrow s a b [a0] Source # many :: StateArrow s a b a0 -> StateArrow s a b [a0] Source #
ArrowPlus a => Semigroup (StateArrow s a b c) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods (<>) :: StateArrow s a b c -> StateArrow s a b c -> StateArrow s a b c Source # sconcat :: NonEmpty (StateArrow s a b c) -> StateArrow s a b c Source # stimes :: Integral b0 => b0 -> StateArrow s a b c -> StateArrow s a b c Source #
ArrowPlus a => Monoid (StateArrow s a b c) Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods mempty :: StateArrow s a b c Source # mappend :: StateArrow s a b c -> StateArrow s a b c -> StateArrow s a b c Source # mconcat :: [StateArrow s a b c] -> StateArrow s a b c Source #

runState :: Arrow a => StateArrow s a e b -> a (e, s) (b, s) Source #

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 Source #

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 Source #

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) Source #

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') Source # |
Instance details Defined in Control.Arrow.Transformer.Automaton Methods liftState :: Automaton a' e b -> Automaton a e b Source # elimState :: Automaton a e b -> Automaton a' (e, r) (b, r) Source #
Arrow a => ArrowAddState s (StateArrow s a) a Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods liftState :: a e b -> StateArrow s a e b Source # elimState :: StateArrow s a e b -> a (e, s) (b, s) Source #
(ArrowAddState s a a', ArrowChoice a, ArrowChoice a') => ArrowAddState s (ErrorArrow ex a) (ErrorArrow ex a') Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods liftState :: ErrorArrow ex a' e b -> ErrorArrow ex a e b Source # elimState :: ErrorArrow ex a e b -> ErrorArrow ex a' (e, s) (b, s) Source #
ArrowAddState s a a' => ArrowAddState s (ReaderArrow r a) (ReaderArrow r a') Source # |
Instance details Defined in Control.Arrow.Transformer.Reader Methods liftState :: ReaderArrow r a' e b -> ReaderArrow r a e b Source # elimState :: ReaderArrow r a e b -> ReaderArrow r a' (e, s) (b, s) Source #
(ArrowAddState s a a', Applicative f) => ArrowAddState s (StaticArrow f a) (StaticArrow f a') Source # |
Instance details Defined in Control.Arrow.Transformer.Static Methods liftState :: StaticArrow f a' e b -> StaticArrow f a e b Source # elimState :: StaticArrow f a e b -> StaticArrow f a' (e, s) (b, s) Source #
(ArrowAddState s a a', Monoid w) => ArrowAddState s (WriterArrow w a) (WriterArrow w a') Source # |
Instance details Defined in Control.Arrow.Transformer.Writer Methods liftState :: WriterArrow w a' e b -> WriterArrow w a e b Source # elimState :: WriterArrow w a e b -> WriterArrow w a' (e, s) (b, s) Source #