MENTAL
 Main Menu
 Applications
 Computer Science
 Arrows


Arrows
 ARROWS

The generalization of monads

"Arrows make the input dependence explicit" (John Hughes ).

"When we define the interface to a software component, we want it to reveal as little as possible of its implementation" (John Hughes)



The concept of arrow

An arrow A b c is an abstract structure that represents a computation A of input type b and returns as output a type c.


Arrows are related to functions, but they are not functions. They are categories of functions: input b and output c functions. The arrows do not explain or detail how c is obtained from b. The arrows are declarative.

The concept of arrow is more general than that of morphism (also called "arrow") in category theory. A morphism is a relation between an object A toward another object B of a category and is represented as AB.

Arrows provide a discipline for structuring programs. They use the analogy of the circuit. The Arrows language looks like a hardware definition language. Programs look static and you don't see how data is processed.

There are different types of arrows: splitters, switches, delays, integrators, arrow function converters (liftings), etc.


Arrows vs. Monads
Arrow operations
  1. arr. It is the main constructor. It converts a function into an arrow.
    If we have a function of type bc, we can construct the arrow of type A b c (we can read it as the arrow A of source b and end c).

      Definition: arr :: (bc) → A b c

  2. >>>. This is the arrow composition operator. It is equivalent to ">>=" (bind) of monads. It puts two arrows in sequence, connecting the output of the first arrow to the input of the second arrow.


      Definition: & >>>> :: A b cA c dA b d

    If the first arrow is of type A b c, the second arrow must be of type A c d. The resulting arrow is of type A b d.

  3. first. Generalizes a (dynamic) arrow A b c into another arrow with a static part d (present at input and output) as the second input and output component.


      Definition: first :: A b cA (b d) (c d)

  4. second. It is the dual operation of first. It generalizes a (dynamic) arrow A b c into another arrow with a static part d (present at input and output) as the first input and output component.


      Definition: second :: A b cA (d b) (d c)

  5. ***. Merges two arrows into one, with two types of components.

      Definition: *** ::: A b cA u vA (b u) (c v)

  6. &&&. Combines two arrows that have the same input into one arrow with both outputs.

      Definition: &&&& :: A b cA b dA b (c d)
There are really only three primitive combinations, which are the first three. The other three are derived combinations. For example, *** is the combination of first and second.


Example

We have the following chart:


A x y (input arrow x and output y)
A x z (input arrow x and output z)
y+z (sum of the outputs of both arrows)


Arrow transformers.

An arrow transformer is a type of arrow parameterized over another type of arrow, so that arrows of the second type can be matched with arrows of the first type. In fact, this corresponds to the concept of a functor in category theory. With this mechanism it is possible to construct an infinite variety of arrows.


Implementation in MENTAL

In MENTAL, we can make the following considerations:

Addenda

Origin of arrows

The arrow concept was introduced by John Hughes [2000, 2005], as a generalization of the monad concept for the Haskell functional language, motivated by the search for an efficient parser, as an alternative to monad-based parsers, which were inefficient and memory-consuming.

Hughes was particularly inspired by the syntactic parser designed by Swierstra and Duponcheel [1996], which consisted of two sequential components: a fast (static) one, which evaluated in a general way whether the input was worth parsing, and a slow (dynamic) one that performed the detail work. The notation Hughes used was point-free.

Ross Patterson [2001] introduced a new, more user-friendly notation with which some laws could be expressed directly. But this new notation turned out to be insufficient for the general treatment of arrows.

Although Hughes' paper appeared in 2000, with the parsers arrow style, a practical implementation did not become available until May 2005: PArrows, developed by Einar Karttunen.

Since Hughes published his first definition in 2000, the laws and operations have been redefined several times. Recent formalizations [Lindley et al. 2010] require only 5 laws.


Applications of arrows

Arrows are being applied in: parsers, circuit design, and metaprogramming (programs that generate programs). And also in two special fields:
Bibliography