arrows-0.4.4.2: Arrow classes and transformers

Copyright(c) Ross Paterson 2003
LicenseBSD-style (see the LICENSE file in the distribution)
MaintainerR.Paterson@city.ac.uk
Stabilityexperimental
Portabilitynon-portable (multi-parameter type classes)
Safe HaskellSafe
LanguageHaskell98

Control.Arrow.Transformer.Writer

Description

Arrow transformer that adds accumulation of output.

Synopsis

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

(ArrowError ex a, Monoid w) => ArrowError ex (WriterArrow w a) Source # 

Methods

raise :: WriterArrow w a ex b Source #

handle :: WriterArrow w a e b -> WriterArrow w a (e, ex) b -> WriterArrow w a e b Source #

tryInUnless :: WriterArrow w a e b -> WriterArrow w a (e, b) c -> WriterArrow w a (e, ex) c -> WriterArrow w a e c Source #

newError :: WriterArrow w a e b -> WriterArrow w a e (Either ex b) Source #

(Arrow a, Monoid w) => ArrowWriter w (WriterArrow w a) Source # 

Methods

write :: WriterArrow w a w () Source #

newWriter :: WriterArrow w a e b -> WriterArrow w a e (b, w) Source #

(ArrowState s a, Monoid w) => ArrowState s (WriterArrow w a) Source # 

Methods

fetch :: WriterArrow w a e s Source #

store :: WriterArrow w a s () Source #

(ArrowReader r a, Monoid w) => ArrowReader r (WriterArrow w a) Source # 

Methods

readState :: WriterArrow w a b r Source #

newReader :: WriterArrow w a e b -> WriterArrow w a (e, r) b Source #

(Arrow a, Monoid w) => ArrowAddWriter w (WriterArrow w a) a Source # 

Methods

liftWriter :: a e b -> WriterArrow w a e b Source #

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

(ArrowAddError ex a a', Monoid w) => ArrowAddError ex (WriterArrow w a) (WriterArrow w a') Source # 

Methods

liftError :: WriterArrow w a' e b -> WriterArrow w a e b Source #

elimError :: WriterArrow w a e b -> WriterArrow w a' (e, ex) b -> WriterArrow w a' e b Source #

(ArrowAddReader r a a', Monoid w) => ArrowAddReader r (WriterArrow w a) (WriterArrow w a') Source # 

Methods

liftReader :: WriterArrow w a' e b -> WriterArrow w a e b Source #

elimReader :: WriterArrow w a e b -> WriterArrow w a' (e, r) b Source #

(ArrowAddState s a a', Monoid w) => ArrowAddState s (WriterArrow w a) (WriterArrow w a') Source # 

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 #

(Arrow a, Monoid w) => ArrowTransformer (WriterArrow w) a Source # 

Methods

lift :: a b c -> WriterArrow w a b c Source #

(Arrow a, Monoid w) => Category * (WriterArrow w a) Source # 

Methods

id :: cat a a #

(.) :: cat b c -> cat a b -> cat a c #

(Arrow a, Monoid w) => Arrow (WriterArrow w a) Source # 

Methods

arr :: (b -> c) -> WriterArrow w a b c #

first :: WriterArrow w a b c -> WriterArrow w a (b, d) (c, d) #

second :: WriterArrow w a b c -> WriterArrow w a (d, b) (d, c) #

(***) :: WriterArrow w a b c -> WriterArrow w a b' c' -> WriterArrow w a (b, b') (c, c') #

(&&&) :: WriterArrow w a b c -> WriterArrow w a b c' -> WriterArrow w a b (c, c') #

(ArrowZero a, Monoid w) => ArrowZero (WriterArrow w a) Source # 

Methods

zeroArrow :: WriterArrow w a b c #

(ArrowPlus a, Monoid w) => ArrowPlus (WriterArrow w a) Source # 

Methods

(<+>) :: WriterArrow w a b c -> WriterArrow w a b c -> WriterArrow w a b c #

(ArrowChoice a, Monoid w) => ArrowChoice (WriterArrow w a) Source # 

Methods

left :: WriterArrow w a b c -> WriterArrow w a (Either b d) (Either c d) #

right :: WriterArrow w a b c -> WriterArrow w a (Either d b) (Either d c) #

(+++) :: WriterArrow w a b c -> WriterArrow w a b' c' -> WriterArrow w a (Either b b') (Either c c') #

(|||) :: WriterArrow w a b d -> WriterArrow w a c d -> WriterArrow w a (Either b c) d #

(ArrowApply a, Monoid w) => ArrowApply (WriterArrow w a) Source # 

Methods

app :: WriterArrow w a (WriterArrow w a b c, b) c #

(ArrowLoop a, Monoid w) => ArrowLoop (WriterArrow w a) Source # 

Methods

loop :: WriterArrow w a (b, d) (c, d) -> WriterArrow w a b c #

(ArrowCircuit a, Monoid w) => ArrowCircuit (WriterArrow w a) Source # 

Methods

delay :: b -> WriterArrow w a b b Source #

(Arrow a, Monoid w) => Functor (WriterArrow w a b) Source # 

Methods

fmap :: (a -> b) -> WriterArrow w a b a -> WriterArrow w a b b #

(<$) :: a -> WriterArrow w a b b -> WriterArrow w a b a #

(Arrow a, Monoid w) => Applicative (WriterArrow w a b) Source # 

Methods

pure :: a -> WriterArrow w a b a #

(<*>) :: WriterArrow w a b (a -> b) -> WriterArrow w a b a -> WriterArrow w a b b #

liftA2 :: (a -> b -> c) -> WriterArrow w a b a -> WriterArrow w a b b -> WriterArrow w a b c #

(*>) :: WriterArrow w a b a -> WriterArrow w a b b -> WriterArrow w a b b #

(<*) :: WriterArrow w a b a -> WriterArrow w a b b -> WriterArrow w a b a #

(ArrowPlus a, Monoid w) => Alternative (WriterArrow w a b) Source # 

Methods

empty :: WriterArrow w a b a #

(<|>) :: WriterArrow w a b a -> WriterArrow w a b a -> WriterArrow w a b a #

some :: WriterArrow w a b a -> WriterArrow w a b [a] #

many :: WriterArrow w a b a -> WriterArrow w a b [a] #

(ArrowPlus a, Monoid w) => Semigroup (WriterArrow w a b c) Source # 

Methods

(<>) :: WriterArrow w a b c -> WriterArrow w a b c -> WriterArrow w a b c #

sconcat :: NonEmpty (WriterArrow w a b c) -> WriterArrow w a b c #

stimes :: Integral b => b -> WriterArrow w a b c -> WriterArrow w a b c #

(ArrowPlus a, Monoid w) => Monoid (WriterArrow w a b c) Source # 

Methods

mempty :: WriterArrow w a b c #

mappend :: WriterArrow w a b c -> WriterArrow w a b c -> WriterArrow w a b c #

mconcat :: [WriterArrow w a b c] -> WriterArrow w a b c #

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')

Minimal complete definition

liftWriter, elimWriter

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 # 

Methods

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

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

(Arrow a, Monoid w) => ArrowAddWriter w (WriterArrow w a) a Source # 

Methods

liftWriter :: a e b -> WriterArrow w a e b Source #

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

(ArrowAddWriter w a a', ArrowChoice a, ArrowChoice a') => ArrowAddWriter w (ErrorArrow ex a) (ErrorArrow ex a') Source # 

Methods

liftWriter :: ErrorArrow ex a' e b -> ErrorArrow ex a e b Source #

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

ArrowAddWriter s a a' => ArrowAddWriter s (ReaderArrow r a) (ReaderArrow r a') Source # 

Methods

liftWriter :: ReaderArrow r a' e b -> ReaderArrow r a e b Source #

elimWriter :: ReaderArrow r a e b -> ReaderArrow r a' e (b, s) Source #

ArrowAddWriter w a a' => ArrowAddWriter w (StateArrow s a) (StateArrow s a') Source # 

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 #

(ArrowAddWriter w a a', Applicative f) => ArrowAddWriter w (StaticArrow f a) (StaticArrow f a') Source # 

Methods

liftWriter :: StaticArrow f a' e b -> StaticArrow f a e b Source #

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