Skip to content

Commit

Permalink
Add arrow laws
Browse files Browse the repository at this point in the history
  • Loading branch information
knuton committed Oct 29, 2013
1 parent dd60a7a commit 1ed1736
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion report/chapters/arrows-practice.tex
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,29 @@ \section{Arrows in Haskell}
signature,

\begin{code}
(&&&) :: Arrow a => a b c -> a b d -> a b (c, d)\textrm{.}
(***) :: Arrow a => a b c -> a b' c' -> a (b, b') (c, c')\textrm{.}
\end{code}

In addition to the constraints expressed by the type class, the semantics of the
functions are subject to a set of laws, the \emph{arrow laws}, which need to be
verified by the author of each instance's implementation.

\begin{code}[numbers=left]
(a >>> b) >>> c == a >>> (b >>> c)
arr (g . f) == arr f >>> arr g
arr id >>> a == a
a == a >>> arr id
first a >>> arr fst == arr fst >>> a
first a >>> arr (id *** f) == arr (id *** f) >>> first a
first (first a) >>> arr assoc == arr assoc >>> first a
first (arr f) == arr (f *** id)
first (a >>> b) == first a >>> first b
\end{code}

The function \verb|assoc| translates tuples \verb|((a,b),c)| to
\verb|(a,(b,c))|, and the functions \verb|fst| and \verb|snd| produce the first
and second position of a tuple, respectively.

The obvious instance of \verb|Arrow| is the pure function type \verb|(->)|. With
\verb|(.)| being the composition function for pure functions, functions of the
adequate types can be given by
Expand Down

0 comments on commit 1ed1736

Please sign in to comment.