Contents

### Context

#### Mapping space

internal hom/mapping space

# Contents

## Idea

In a cartesian closed category/type theory $\mathcal{C}$, given any object/type $W$ there is a comonad

$W \times (-) \colon \mathcal{C} \to \mathcal{C}$

given by forming the Cartesian product with $W$, with the coproduct induced by the diagonal map on $W$ and the counit induced by the terminal map $W \to \ast$.

Notice then if $W$ is furthermore equipped with the structure of a monoid, then $W \times (-)$ also canonically inherits the structure of a monad, allowing aggregation of a program’s $W$ outputs, corresponding to a sort of side channel. Equipped with this monad-structure, the operation $W \times (-)$ is known as the writer monad, see there for more.

On the other hand, the canonical comonad structure on $W \times (-)$ is left adjoint to the reader monad, so that it is known as the reader comonad (eg. in the Haskell documentation for Control.Comonad.Reader) or coreader comonad (e.g. Ahman & Uustalu (2019)). It is also known as the product comonad (e.g. Uustalu & Vene 2008, p. 270).

## Properties

In a cartesian closed category/type theory $\mathcal{C}$, the coreader comonad $W\times (-)$ is left adjoint to the reader monad $[W,-]$.

### In terms of dependent type theory

If the type system is even a locally Cartesian closed category/dependent type theory then for each type $W$ there is the base change adjoint triple

$\mathcal{C}_{/W} \stackrel{\overset{\sum_W}{\longrightarrow}}{\stackrel{\overset{W^\ast}{\longleftarrow}}{\underset{\prod_W}{\longrightarrow}}} \mathcal{C}$

In terms of this then the coreader comonad is equivalently the composite

$\sum_W W^\ast = W\times (-) \;\colon\; \mathcal{C} \longrightarrow \mathcal{C}$

of context extension followed by dependent sum.

One may also think of this as being the integral transform through the span

$\ast \leftarrow W \rightarrow \ast$

(with trivial kernel) or as the polynomial functor associated with the span

$\ast \leftarrow W \stackrel{id}{\rightarrow} W \rightarrow \ast \,.$

Eg.