3
$\begingroup$

First, some background: recently in learning more about functional programming I saw one use for coproducts that surprised me a little bit: A function $f: A \rightarrow B \coprod C$ may result when considering a computation that starts with an $a \in A$ and results with an element of $B$ unless "something exceptional happens" in which case it results in an element in $C$ that describes / paramaterizes some sort of

  • computational defect
  • failure mode
  • deformity
  • irregularity .

This was surprising because before that point I had considered the two sides of a coproduct to be reversible, but they can no longer be considered so if the first set is designated as the collection of "normal" outputs and the second set is designated as paramaterizing an "exceptional" result.

My question: are there other places where an function/arrow to a coproduct is viewed as an alternative between a normal/regular outcome on one side and an exceptional/irregular outcome on the other? Though I can't think of many right now, I'm guessing there must be computations (etc) where coproducts have an asymmetric normal vs irregular interpretation.

$\endgroup$

3 Answers 3

8
$\begingroup$

This interpretation of $C$ as a place to report failures doesn't really have teeth until you see how it interacts with function composition, which is the following. Suppose $f : X \to Y \coprod C$ and $g : Y \to Z \coprod C$ are two "functions with $C$-valued failures." Then I claim that there is a meaningful way to compose them to get a function $g \circ_C f : X \to Z \coprod C$, as follows: take the composite

$$X \xrightarrow{f} Y \coprod C \xrightarrow{g \text{ or } i_C} Z \coprod C$$

where $g \text{ or } i_C$ is my awkward notation for the function $Y \coprod C \to Z \coprod C$ which on $Y$ is $g$ and on $C$ is the inclusion map $i_C : C \to Z \coprod C$. In particular, the definition of this notion of composition treats $C$ differently from every other object that occurs. This is what breaks the symmetry between $C$ and the other term in the coproduct.

Intuitively, this notion of composition reports the first failure in a sequence of computations, then stops.

This is a special case of Kleisli composition with respect to a monad, which in this case is $T(-) = (-) \coprod C$. I believe in computer science this is called the Error monad. It generalizes the Maybe monad.

$\endgroup$
6
$\begingroup$

There is a dual example: a map $f : S \times A \to B$ may be seen as a map $A \to B$ which takes an additional parameter from $S$. Again, the meat is in the composition of such arrows. Given $f : S \times A \to B$ and $g : S \times B \to C$ we may compose them to $g * f : S \times A \to C$ by $(s, a) \mapsto g (s, f (s, a))$, and in computer science this is known as the reader monad.

Its purpose is to make the parameter $s \in S$ available throughout the computation without having to pass it around explicitly all the time, by using the monad structure with the do notation. There are a lot of neat things functional programmers do with category theory (and some insane ones).

$\endgroup$
0
$\begingroup$

Presumably closely related are partial map classifiers which can be viewed as the version of the question in case it is not decidable whether "something exceptional" will happen. A partial map is just like a map - it is a functional (i. e. single valued) relation $\subseteq A\times B$ which is not necessarily total. That is, writing $f(a)=b$ when $(a,b)$ belongs to the relation, it is true that $f(a)=b_1$ and $f(a)=b_2$ imply $b_1=b_2$ but one does not require that for each $a$ there is a $b$ with $f(a)=b$.

In some cases (e. g. in a topos) partial maps are representable: there is a $\tilde B$ such that partial maps from $A$ to $B$ are in one-to-one correspondence with "ordinary" maps $A\to\tilde B$.

In "boolean" situations one may take $\tilde B=B\coprod1$ but in general $\tilde B$ may contain lots of things besides $B$, and it might be impossible to sort out which of these things belong to $B$ and which don't.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .