Portability | non-portable (multi-parameter type classes) |
---|---|

Stability | experimental |

Maintainer | ross@soi.city.ac.uk |

Safe Haskell | Safe-Inferred |

Subclasses of `Arrow`

providing additional operations.

The signatures are designed to be compatible with the proposed notation for arrows, cf. http://www.haskell.org/arrows/.

- class Arrow a => ArrowState s a | a -> s where
- class Arrow a => ArrowReader r a | a -> r where
- class (Monoid w, Arrow a) => ArrowWriter w a | a -> w where
- class Arrow a => ArrowError ex a | a -> ex where
- raise :: a ex b
- handle :: a e b -> a (e, ex) b -> a e b
- tryInUnless :: a e b -> a (e, b) c -> a (e, ex) c -> a e c
- newError :: a e b -> a e (Either ex b)

- tryInUnlessDefault :: (ArrowError ex a, ArrowChoice a) => a e b -> a (e, b) c -> a (e, ex) c -> a e c
- class ArrowLoop a => ArrowCircuit a where
- delay :: b -> a b b

# Conventions

The arrow classes defined in this module have names like `Arrow`

*Foo*,
and contain operations specific to such arrows. Some of these include
a method `new`

*Foo*, which maps computations to computations of the
same arrow type, but exposing some of the internals of the arrow.

Arrow transformers have names like *Bar*`Arrow`

, and are
instances of appropriate arrow classes. For each arrow
transformer, there is typically an encapsulation operator
`run`

*Bar* that removes that transformer from the outside of an
arrow type. The `lift`

method of the
`ArrowTransformer`

class adds an arrow
transformer to the outside of an arrow type.

Typically a composite arrow type is built by applying a series of arrow
transformers to a base arrow (usually either a function arrow or a
`Kleisli`

arrow. The `lift`

method and the
`run`

*Bar* function operate only on the arrow transformer at the top
of this stack. For more sophisticated manipulation of this stack of
arrow transformers, many arrow transformers provide an `ArrowAdd`

*Bar*
class, with methods methods `lift`

*Bar* and `elim`

*Bar* to add and remove
the transformer anywhere in the stack.

# State transformers

class Arrow a => ArrowState s a | a -> s whereSource

An arrow type that provides a modifiable state,
based of section 9 of *Generalising Monads to Arrows*, by John Hughes,
*Science of Computer Programming* 37:67-111, May 2000.

Obtain the current value of the state.

Assign a new value to the state.

(Arrow (Automaton a), ArrowState s a) => ArrowState s (Automaton a) | |

(Arrow (StreamArrow a), ArrowState s a) => ArrowState s (StreamArrow a) | |

(Arrow (ErrorArrow ex a), ArrowState s a, ArrowChoice a) => ArrowState s (ErrorArrow ex a) | |

(Arrow (StateArrow s a), Arrow a) => ArrowState s (StateArrow s a) | |

(Arrow (StaticArrow f a), ArrowState s a, Applicative f) => ArrowState s (StaticArrow f a) | |

(Arrow (WriterArrow w a), ArrowState s a, Monoid w) => ArrowState s (WriterArrow w a) | |

(Arrow (ReaderArrow r a), ArrowState s a) => ArrowState s (ReaderArrow r a) |

# State readers

class Arrow a => ArrowReader r a | a -> r whereSource

An arrow type that provides a read-only state (an environment).
If you also need to modify the state, use `ArrowState`

.

Obtain the current value of the state.

newReader :: a e b -> a (e, r) bSource

Run a subcomputation in the same arrow, but with a different environment. The environment of the outer computation is unaffected.

Typical usage in arrow notation:

proc p -> ... (|newReader cmd|) env

(Arrow (Automaton a), ArrowReader r a) => ArrowReader r (Automaton a) | |

(Arrow (ErrorArrow ex a), ArrowReader r a, ArrowChoice a) => ArrowReader r (ErrorArrow ex a) | |

(Arrow (StateArrow s a), ArrowReader r a) => ArrowReader r (StateArrow s a) | |

(Arrow (StaticArrow f a), ArrowReader r a, Applicative f) => ArrowReader r (StaticArrow f a) | |

(Arrow (WriterArrow w a), ArrowReader r a, Monoid w) => ArrowReader r (WriterArrow w a) | |

(Arrow (ReaderArrow r a), Arrow a) => ArrowReader r (ReaderArrow r a) |

# Monoid writers

class (Monoid w, Arrow a) => ArrowWriter w a | a -> w whereSource

An arrow type that collects additional output (of some `Monoid`

type).

Add a piece of additional output.

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

Run a subcomputation in the same arrow, making its additional output accessible.

Typical usage in arrow notation:

proc p -> do ... (value, output) <- (|newWriter cmd|)

(Monoid w, Arrow (Automaton a), ArrowWriter w a) => ArrowWriter w (Automaton a) | |

(Monoid w, Arrow (StreamArrow a), ArrowWriter w a) => ArrowWriter w (StreamArrow a) | |

(Monoid w, Arrow (ErrorArrow ex a), ArrowWriter w a, ArrowChoice a) => ArrowWriter w (ErrorArrow ex a) | |

(Monoid w, Arrow (StateArrow s a), ArrowWriter w a) => ArrowWriter w (StateArrow s a) | |

(Monoid w, Arrow (StaticArrow f a), ArrowWriter w a, Applicative f) => ArrowWriter w (StaticArrow f a) | |

(Arrow (WriterArrow w a), Arrow a, Monoid w) => ArrowWriter w (WriterArrow w a) | |

(Monoid s, Arrow (ReaderArrow r a), ArrowWriter s a) => ArrowWriter s (ReaderArrow r a) |

# Errors

class Arrow a => ArrowError ex a | a -> ex whereSource

An arrow type that includes errors (or exceptions).

Minimal definition: `raise`

and `tryInUnless`

.

*TODO:* the operations here are inconsistent with other arrow transformers.

Raise an error.

:: a e b | computation that may raise errors |

-> a (e, ex) b | computation to handle errors |

-> a e b |

Traditional exception construct.

Typical usage in arrow notation:

proc p -> ... body `handle` \ex -> handler

:: a e b | computation that may raise errors |

-> a (e, b) c | computation to receive successful results |

-> a (e, ex) c | computation to handle errors |

-> a e c |

Exception construct in the style of *Exceptional Syntax*,
by Nick Benton and Andrew Kennedy, *JFP* 11(4):395-410, July 2001.

Typical usage in arrow notation:

proc p -> ... (|tryInUnless body (\res -> success) (\ex -> handler) |)

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

Handler that returns the error as a value.

(Arrow (Automaton a), ArrowError r a) => ArrowError r (Automaton a) | |

(Arrow (ErrorArrow ex a), ArrowChoice a) => ArrowError ex (ErrorArrow ex a) | |

(Arrow (StateArrow s a), ArrowError ex a) => ArrowError ex (StateArrow s a) | |

(Arrow (StaticArrow f a), ArrowError ex a, Applicative f) => ArrowError ex (StaticArrow f a) | |

(Arrow (WriterArrow w a), ArrowError ex a, Monoid w) => ArrowError ex (WriterArrow w a) | |

(Arrow (ReaderArrow r a), ArrowError ex a) => ArrowError ex (ReaderArrow r a) |

:: (ArrowError ex a, ArrowChoice a) | |

=> a e b | computation that may raise errors |

-> a (e, b) c | computation to receive successful results |

-> a (e, ex) c | computation to handle errors |

-> a e c |

A suitable value for `tryInUnless`

when the arrow type belongs to
`ArrowChoice`

. To use it, you must define either `handle`

or `newError`

.

# Synchronous circuits

class ArrowLoop a => ArrowCircuit a whereSource

An arrow type that can be used to interpret synchronous circuits.

:: b | the value to return initially. |

-> a b b | an arrow that propagates its input with a one-tick delay. |

A delay component.

(ArrowLoop (Automaton a), ArrowLoop a) => ArrowCircuit (Automaton a) | |

(ArrowLoop (StreamArrow a), ArrowLoop a) => ArrowCircuit (StreamArrow a) | |

(ArrowLoop (StateArrow s a), ArrowCircuit a) => ArrowCircuit (StateArrow s a) | |

(ArrowLoop (StaticArrow f a), ArrowCircuit a, Applicative f) => ArrowCircuit (StaticArrow f a) | |

(ArrowLoop (WriterArrow w a), ArrowCircuit a, Monoid w) => ArrowCircuit (WriterArrow w a) | |

(ArrowLoop (ReaderArrow r a), ArrowCircuit a) => ArrowCircuit (ReaderArrow r a) |