Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What about arrows?

Tags:

haskell

Reading through various tutorials about Haskell's various category-themed classes, we find things like Monoid, Functor, Monad and so on - all of which have dozens of instances. But for some reason, when we reach Arrow, there are only two instances: functions and monads. In both cases, using the Arrow instance is less powerful and more difficult than just using the underlying thing directly.

Does anybody have any interesting examples of arrows? I'm sure there must be some, but I've never come across any writing about them...

like image 520
MathematicalOrchid Avatar asked Apr 04 '14 19:04

MathematicalOrchid


People also ask

Why are arrows so important?

The most common association with the arrow is its use as a tool for hunting and protection. And while it was naturally considered a tool of war due to its status as a weapon, the arrow was also a symbol of peace and other philosophical ideas.

What are the 3 types of arrows?

If we classify arrows according to their material, then there are four main types: wooden arrows, aluminium arrows, carbon arrows and aluminium carbon arrows. But there are also arrows made of fibreglass. These wooden arrows are mainly designed for the traditional bow and the longbow.

What is the use of an arrow?

a slender, straight, generally pointed missile or weapon made to be shot from a bow and equipped with feathers at the end of the shaft near the nock, for controlling flight.

What arrows mean?

Arrows are universally recognised for indicating directions. They are widely used on signage and for wayfinding, and are often used in road surface markings. Upward arrows are often used to indicate an increase in a numerical value, and downward arrows indicate a decrease.


1 Answers

I like to think of Arrows as composable directed acyclic graphs. For example, an arrow of type:

SomeArrow (a, b, c) (d, e, f)

... you can think of as a graph that has three incoming edges of type a, b, and c and three outgoing edges of type d, e, and f.

Using this interpretation, the category composition operations for Arrows are like horizontal concatenation for graphs, connecting their edges together:

(.) :: SomeArrow b c -> SomeArrow a b -> Some Arrow a c

... where a, b, and c may be themselves tuples. Similarly, id is just the identity graph that forwards all incoming edges to outgoing edges:

id :: SomeArrow a a

The other key operation is (***) which is like vertical concatenation of graphs:

(***) :: Arrow a b -> Arrow c d -> Arrow (a, c) (b, d)

You can think of that as putting two graphs side-by-side, combining their input edges and output edges.

So Arrow commonly arise when working with typed directed acyclic graphs. However, the reason you usually don't see them that often is because most people mentally associate graphs with untyped and high-performance data structures.

like image 189
Gabriella Gonzalez Avatar answered Oct 11 '22 12:10

Gabriella Gonzalez