e01.org

Arrow (computer science)

In computer science, arrows or bolts are a type class used in computer programming to describe computations in a pure and declarative fashion. First proposed by computer scientist John Hughes as a generalization of monads, arrows provide a referentially transparent way to express relationships between logical steps in a computation. Unlike monads, arrows don't limit steps to having one and only one input. As a result, they have found use in functional reactive programming, tacit programming (point-free style), parsers, and in other uses. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

In computer science, arrows or bolts are a type class used in computer programming to describe computations in a pure and declarative fashion. First proposed by computer scientist John Hughes as a generalization of monads, arrows provide a referentially transparent way to express relationships between logical steps in a computation. Unlike monads, arrows don't limit steps to having one and only one input. As a result, they have found use in functional reactive programming, tacit programming (point-free style), parsers, and in other uses. arr : (s -> t) -> A s t A piping method that takes an arrow between two types and converts it into an arrow between tuples. The first elements in the tuples represent the portion of the input and output that is altered, while the second elements are a third type describing an unaltered portion that bypasses the computation. first : A s t -> A (s,u) (t,u) As all arrows must be categories, they inherit a third operation from the class of categories: A composition operator that can attach a second arrow to a first as long as the first function's output and the second's input have matching types. (>>>) : A s t -> A t u -> A s u Although only these three procedures are strictly needed to define an arrow, other methods can be derived to make arrows easier to work with in practice and theory. One more helpful method can be derived from and (and from which can be derived): A merging operator that takes two arrows, possibly with different input and output types, and fuses them into one arrow between two compound types. The merge operator is not necessarily commutative. (***) : A s t -> A u v -> A (s,u) (t,v) arr id == id When connecting two functions & , the required arrow operations must distribute over compositions from the left. arr (f >>> g) == arr f >>> arr g first (f >>> g) == first f >>> first g In the previous laws, piping can be applied directly to functions because order must be irrelevant when piping & lifting occur together. arr (first f) == first (arr f) The remaining laws restrict how the piping method behaves when the order of a composition is reversed, also allowing for simplifying expressions: If an identity is merged with a second function to form an arrow, attaching it to a piped function must be commutative. arr (id *** g) >>> first f == first f >>> arr (id *** g) Piping a function before type simplification must be equivalent to simplifying type before connecting to the unpiped function. first f >>> arr ((s,t) -> s) == arr ((s,t) -> s) >>> f Finally, piping a function twice before reassociating the resulting tuple, which is nested, should be the same as reassociating the nested tuple before attaching a single bypass of the function. In other words, stacked bypasses can be flattened by first bundling together those elements unchanged by the function. first (first f) >>> arr ( ((s,t),u) -> (s,(t,u)) ) == arr ( ((s,t),u) -> (s,(t,u)) ) >>> first f

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Arrow (computer science)". 1755836290. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1307204485

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·