Arrow (computer science)
|
|
This article includes a list of references, related reading or external links, but its sources remain unclear because it lacks inline citations. Please improve this article by introducing more precise citations. (December 2010) |
|
|
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (December 2010) |
In computer science, arrows provide a more general interface to computation than monads. Monads essentially provide a sequential interface to computation: one can build a computation out of a value, or sequence two computations. Arrows provide more possibilities, including expressing (true, nondeterministic) parallel computation. Indeed, monads turn out to be equivalent to arrows of a particular kind, ArrowApply. Because arrows carry more type information than just the result type, composition can be more efficient—for example, eliminating space leaks.
Arrows have found use in functional reactive programming.
Contents |
[edit] Definition
As a prerequisite, we define a category of types. It is given by:
- a type constructor
which takes two type parameters - for any type A, an object

- for any three types A, B, C an operator

subject to the following laws:
Note that
defines a category of types, with the obvious choices for
and
.
Alternative notations are defined for the composition operator:

.
An arrow is a category of types endowed with the following functions:




;
subject to the following laws:
where the
category of types is extended to an arrow as follows:
[edit] Arrows with choice
We may extend the arrow construct with the ability to choose between alternative computation paths. An arrow with choice is characterized by the following functions:



;
subject to the following laws:
where the
arrow is endowed with the following definition:
[edit] Arrows with application
Arrows with application extend the basic arrow type with an application morphism:
The
arrow has an application morphism, apply:
[edit] Kleisli arrows
For any monad M, functions of type
form a category of types, called the Kleisli category for the monad. Its definition is as follows:
The Kleisli category is also an arrow:
The Kleisli category is an arrow with choice:

where 
where 
where 
The Kleisli category is an arrow with application:
Conversely, given any arrow with application, the corresponding monad
(where
denotes the unit type) is defined by the following functions:
The fmap and join functions are:
| The Wikibook Haskell has a page on the topic of |
[edit] External links
- Arrows: A General Interface to Computation
- “Generalising Monads to Arrows”, John Hughes, in Science of Computer Programming 37, pp67–111, May 2000.
- A New Notation for Arrows, Ross Paterson, in ICFP, Sep 2001.
- Arrows and Computation, Ross Paterson, in The Fun of Programming, Palgrave, 2003.
- Arrow notation ghc manual
which takes two type parameters




.



;














;






















where 
where 
where 




