arrows-0.4.4.1: Arrow classes and transformers

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

Control.Arrow.Transformer.Writer

Description

Arrow transformer that adds accumulation of output.

Synopsis

- newtype WriterArrow w a b c = WriterArrow (a b (c, w))
- runWriter :: (Arrow a, Monoid w) => WriterArrow w a e b -> a e (b, w)
- class (ArrowWriter w a, Arrow a') => ArrowAddWriter w a a' | a -> a' where
  - liftWriter :: a' e b -> a e b
  - elimWriter :: a e b -> a' e (b, w)

# Documentation

newtype WriterArrow w a b c Source

An arrow type that augments an existing arrow with accumulating output. The `ArrowWriter` class contains the relevant operations.

Constructors

WriterArrow (a b (c, w)) |

Instances

(Arrow a, Monoid w) => Category * (WriterArrow w a) Source |
(ArrowError ex a, Monoid w) => ArrowError ex (WriterArrow w a) Source |
(Arrow a, Monoid w) => ArrowWriter w (WriterArrow w a) Source |
(ArrowState s a, Monoid w) => ArrowState s (WriterArrow w a) Source |
(ArrowReader r a, Monoid w) => ArrowReader r (WriterArrow w a) Source |
(Arrow a, Monoid w) => ArrowAddWriter w (WriterArrow w a) a Source |
(ArrowAddError ex a a', Monoid w) => ArrowAddError ex (WriterArrow w a) (WriterArrow w a') Source |
(ArrowAddReader r a a', Monoid w) => ArrowAddReader r (WriterArrow w a) (WriterArrow w a') Source |
(ArrowAddState s a a', Monoid w) => ArrowAddState s (WriterArrow w a) (WriterArrow w a') Source |
(Arrow a, Monoid w) => ArrowTransformer (WriterArrow w) a Source |
(Arrow a, Monoid w) => Arrow (WriterArrow w a) Source |
(ArrowZero a, Monoid w) => ArrowZero (WriterArrow w a) Source |
(ArrowPlus a, Monoid w) => ArrowPlus (WriterArrow w a) Source |
(ArrowChoice a, Monoid w) => ArrowChoice (WriterArrow w a) Source |
(ArrowApply a, Monoid w) => ArrowApply (WriterArrow w a) Source |
(ArrowLoop a, Monoid w) => ArrowLoop (WriterArrow w a) Source |
(ArrowCircuit a, Monoid w) => ArrowCircuit (WriterArrow w a) Source |
(Arrow a, Monoid w) => Functor (WriterArrow w a b) Source |
(Arrow a, Monoid w) => Applicative (WriterArrow w a b) Source |
(ArrowPlus a, Monoid w) => Alternative (WriterArrow w a b) Source |
(ArrowPlus a, Monoid w) => Monoid (WriterArrow w a b c) Source |

runWriter :: (Arrow a, Monoid w) => WriterArrow w a e b -> a e (b, w) Source

Encapsulation of a writer computation, providing the accumulated output.

Typical usage in arrow notation:

    	proc p -> do
    		...
    		(result, output) <- (|runWriter cmd|)

class (ArrowWriter w a, Arrow a') => ArrowAddWriter w a a' | a -> a' where Source

Adding a `WriterArrow` 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 `runWriter` encapsulation operator. The methods of this class add and remove state transformers anywhere in the stack. In the instance

    	instance Arrow a => ArrowAddWriter w (ArrowWriter w a) a

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

    	instance ArrowAddWriter w a a' =>
    		ArrowAddWriter w (FooArrow a) (FooArrow a')

Methods

liftWriter :: a' e b -> a e b Source

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

Typical usage in arrow notation:

    	proc p -> ...
    		(|liftWriter cmd|)

elimWriter :: a e b -> a' e (b, w) Source

Elimination of an output writer from a computation, providing the accumulated output.

Typical usage in arrow notation:

    	proc p -> do
    		...
    		(result, output) <- (|elimWriter cmd|)

Instances

ArrowAddWriter w a a' => ArrowAddWriter w (Automaton a) (Automaton a') Source |
(Arrow a, Monoid w) => ArrowAddWriter w (WriterArrow w a) a Source |
(ArrowAddWriter w a a', ArrowChoice a, ArrowChoice a') => ArrowAddWriter w (ErrorArrow ex a) (ErrorArrow ex a') Source |
ArrowAddWriter w a a' => ArrowAddWriter w (StateArrow s a) (StateArrow s a') Source |
(ArrowAddWriter w a a', Applicative f) => ArrowAddWriter w (StaticArrow f a) (StaticArrow f a') Source |
ArrowAddWriter s a a' => ArrowAddWriter s (ReaderArrow r a) (ReaderArrow r a') Source |