arrows-0.4.4.2: Arrow classes and transformers

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

Control.Arrow.Operations

Contents

Description

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/.

Synopsis

Conventions

The arrow classes defined in this module have names like ArrowFoo, and contain operations specific to such arrows. Some of these include a method newFoo, which maps computations to computations of the same arrow type, but exposing some of the internals of the arrow.

Arrow transformers have names like BarArrow, and are instances of appropriate arrow classes. For each arrow transformer, there is typically an encapsulation operator runBar 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 runBar 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 ArrowAddBar class, with methods methods liftBar and elimBar to add and remove the transformer anywhere in the stack.

State transformers

class Arrow a => ArrowState s a | a -> s where Source #

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.

Minimal complete definition

fetch, store

Methods

fetch :: a e s Source #

Obtain the current value of the state.

store :: a s () Source #

Assign a new value to the state.

Instances

ArrowState s a => ArrowState s (Automaton a) Source # 

Methods

fetch :: Automaton a e s Source #

store :: Automaton a s () Source #

ArrowState s a => ArrowState s (StreamArrow a) Source # 

Methods

fetch :: StreamArrow a e s Source #

store :: StreamArrow a s () Source #

(ArrowState s a, ArrowChoice a) => ArrowState s (ErrorArrow ex a) Source # 

Methods

fetch :: ErrorArrow ex a e s Source #

store :: ErrorArrow ex a s () Source #

ArrowState s a => ArrowState s (ReaderArrow r a) Source # 

Methods

fetch :: ReaderArrow r a e s Source #

store :: ReaderArrow r a s () Source #

Arrow a => ArrowState s (StateArrow s a) Source # 

Methods

fetch :: StateArrow s a e s Source #

store :: StateArrow s a s () Source #

(ArrowState s a, Applicative f) => ArrowState s (StaticArrow f a) Source # 

Methods

fetch :: StaticArrow f a e s Source #

store :: StaticArrow f a s () 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 #

State readers

class Arrow a => ArrowReader r a | a -> r where Source #

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

Minimal complete definition

readState, newReader

Methods

readState :: a b r Source #

Obtain the current value of the state.

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

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

Instances

ArrowReader r a => ArrowReader r (Automaton a) Source # 

Methods

readState :: Automaton a b r Source #

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

(ArrowReader r a, ArrowChoice a) => ArrowReader r (ErrorArrow ex a) Source # 

Methods

readState :: ErrorArrow ex a b r Source #

newReader :: ErrorArrow ex a e b -> ErrorArrow ex a (e, r) b Source #

Arrow a => ArrowReader r (ReaderArrow r a) Source # 

Methods

readState :: ReaderArrow r a b r Source #

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

ArrowReader r a => ArrowReader r (StateArrow s a) Source # 

Methods

readState :: StateArrow s a b r Source #

newReader :: StateArrow s a e b -> StateArrow s a (e, r) b Source #

(ArrowReader r a, Applicative f) => ArrowReader r (StaticArrow f a) Source # 

Methods

readState :: StaticArrow f a b r Source #

newReader :: StaticArrow f a e b -> StaticArrow f a (e, r) b 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 #

Monoid writers

class (Monoid w, Arrow a) => ArrowWriter w a | a -> w where Source #

An arrow type that collects additional output (of some Monoid type).

Minimal complete definition

write, newWriter

Methods

write :: a w () Source #

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

Instances

ArrowWriter w a => ArrowWriter w (Automaton a) Source # 

Methods

write :: Automaton a w () Source #

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

ArrowWriter w a => ArrowWriter w (StreamArrow a) Source # 

Methods

write :: StreamArrow a w () Source #

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

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

Methods

write :: ErrorArrow ex a w () Source #

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

ArrowWriter s a => ArrowWriter s (ReaderArrow r a) Source # 

Methods

write :: ReaderArrow r a s () Source #

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

ArrowWriter w a => ArrowWriter w (StateArrow s a) Source # 

Methods

write :: StateArrow s a w () Source #

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

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

Methods

write :: StaticArrow f a w () Source #

newWriter :: StaticArrow f a e b -> StaticArrow f a e (b, w) 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 #

Errors

class Arrow a => ArrowError ex a | a -> ex where Source #

An arrow type that includes errors (or exceptions).

Minimal definition: raise and tryInUnless.

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

Minimal complete definition

raise, tryInUnless

Methods

raise :: a ex b Source #

Raise an error.

handle Source #

Arguments

:: 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

tryInUnless Source #

Arguments

:: 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.

Instances

ArrowError r a => ArrowError r (Automaton a) Source # 

Methods

raise :: Automaton a r b Source #

handle :: Automaton a e b -> Automaton a (e, r) b -> Automaton a e b Source #

tryInUnless :: Automaton a e b -> Automaton a (e, b) c -> Automaton a (e, r) c -> Automaton a e c Source #

newError :: Automaton a e b -> Automaton a e (Either r b) Source #

ArrowChoice a => ArrowError ex (ErrorArrow ex a) Source # 

Methods

raise :: ErrorArrow ex a ex b Source #

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

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

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

ArrowError ex a => ArrowError ex (ReaderArrow r a) Source # 

Methods

raise :: ReaderArrow r a ex b Source #

handle :: ReaderArrow r a e b -> ReaderArrow r a (e, ex) b -> ReaderArrow r a e b Source #

tryInUnless :: ReaderArrow r a e b -> ReaderArrow r a (e, b) c -> ReaderArrow r a (e, ex) c -> ReaderArrow r a e c Source #

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

ArrowError ex a => ArrowError ex (StateArrow s a) Source # 

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 #

(ArrowError ex a, Applicative f) => ArrowError ex (StaticArrow f a) Source # 

Methods

raise :: StaticArrow f a ex b Source #

handle :: StaticArrow f a e b -> StaticArrow f a (e, ex) b -> StaticArrow f a e b Source #

tryInUnless :: StaticArrow f a e b -> StaticArrow f a (e, b) c -> StaticArrow f a (e, ex) c -> StaticArrow f a e c Source #

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

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

tryInUnlessDefault Source #

Arguments

:: (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 where Source #

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

Minimal complete definition

delay

Methods

delay Source #

Arguments

:: b

the value to return initially.

-> a b b

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

A delay component.

Instances

ArrowLoop a => ArrowCircuit (Automaton a) Source # 

Methods

delay :: b -> Automaton a b b Source #

ArrowLoop a => ArrowCircuit (StreamArrow a) Source # 

Methods

delay :: b -> StreamArrow a b b Source #

ArrowCircuit a => ArrowCircuit (ReaderArrow r a) Source # 

Methods

delay :: b -> ReaderArrow r a b b Source #

ArrowCircuit a => ArrowCircuit (StateArrow s a) Source # 

Methods

delay :: b -> StateArrow s a b b Source #

(ArrowCircuit a, Applicative f) => ArrowCircuit (StaticArrow f a) Source # 

Methods

delay :: b -> StaticArrow f a b b Source #

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

Methods

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