7.7 Modalities
Nearly all of the theory of $n$types and connectedness can be done in much greater generality. This section^{} will not be used in the rest of the book.
Our first thought regarding generalizing the theory of $n$types might be to take \autorefthm:truncreflective as a definition.
Definition 7.7.1.
A reflective subuniverse is a predicate^{} $P\mathrm{:}\mathrm{U}\mathrm{\to}\mathrm{Prop}$ such that for every $A\mathrm{:}\mathrm{U}$ we have a type $\text{ocircle}\mathit{}A$ such that $P\mathit{}\mathrm{(}\text{ocircle}\mathit{}A\mathrm{)}$ and a map ${\eta}_{A}\mathrm{:}A\mathrm{\to}\text{ocircle}\mathit{}A$, with the property that for every $B\mathrm{:}\mathrm{U}$ with $P\mathit{}\mathrm{(}B\mathrm{)}$, the following map is an equivalence:
$$\{\begin{array}{ccc}\hfill (\text{ocircle}A\to B)& \hfill \u27f6\hfill & (A\to B)\hfill \\ \hfill f& \hfill \u27fc\hfill & f\circ {\eta}_{A}\hfill \end{array}.$$ 
We write $\mathrm{\P}:\equiv \text{setof}A:\mathcal{U}P(A)$, so $A:\mathrm{\P}$ means that $A:\mathcal{U}$ and we have $P(A)$. We also write ${\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}$ for the quasiinverse of the above map. The notation $\text{ocircle}$ may seem slightly odd, but it will make more sense soon.
For any reflective subuniverse, we can prove all the familiar facts about reflective subcategories from category theory^{}, in the usual way. For instance, we have:

•
A type $A$ lies in $\mathrm{\P}$ if and only if ${\eta}_{A}:A\to \text{ocircle}A$ is an equivalence.

•
$\mathrm{\P}$ is closed under^{} retracts. In particular, $A$ lies in $\mathrm{\P}$ as soon as ${\eta}_{A}$ admits a retraction.
 •
 •

•
Colimits^{} in $\mathrm{\P}$ can be constructed by applying $\text{ocircle}$ to ordinary colimits of types.
Importantly, closure^{} under products extends also to “infinite products”, i.e. dependent function types.
Theorem 7.7.2.
If $B\mathrm{:}A\mathrm{\to}\mathrm{\P}$ is any family of types in a reflective subuniverse ¶, then ${\mathrm{\prod}}_{\mathrm{(}x\mathrm{:}A\mathrm{)}}B\mathit{}\mathrm{(}x\mathrm{)}$ is also in ¶.
Proof.
For any $x:A$, consider the function ${\mathrm{\U0001d5be\U0001d5cf}}_{x}:({\prod}_{(x:A)}B(x))\to B(x)$ defined by ${\mathrm{\U0001d5be\U0001d5cf}}_{x}(f):\equiv f(x)$. Since $B(x)$ lies in $P$, this extends to a function
$${\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({\mathrm{\U0001d5be\U0001d5cf}}_{x}):\text{ocircle}\left(\prod _{x:A}B(x)\right)\to B(x).$$ 
Thus we can define $h:\text{ocircle}({\prod}_{(x:A)}B(x))\to {\prod}_{(x:A)}B(x)$ by $h(z)(x):\equiv {\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({\mathrm{\U0001d5be\U0001d5cf}}_{x})(z)$. Then $h$ is a retraction of ${\eta}_{{\prod}_{(x:A)}B(x)}$, so that ${\prod}_{(x:A)}B(x)$ is in $\mathrm{\P}$. ∎
In particular, if $B:\mathrm{\P}$ and $A$ is any type, then $(A\to B)$ is in ¶. In categorical language^{}, this means that any reflective subuniverse is an exponential ideal. This, in turn, implies by a standard argument that the reflector preserves finite products.
Corollary 7.7.3.
For any types $A$ and $B$ and any reflective subuniverse, the induced map $\text{ocircle}\mathit{}\mathrm{(}A\mathrm{\times}B\mathrm{)}\mathrm{\to}\text{ocircle}\mathit{}\mathrm{(}A\mathrm{)}\mathrm{\times}\text{ocircle}\mathit{}\mathrm{(}B\mathrm{)}$ is an equivalence.
Proof.
It suffices to show that $\text{ocircle}(A)\times \text{ocircle}(B)$ has the same universal property^{} as $\text{ocircle}(A\times B)$. Thus, let $C:\mathrm{\P}$; we have
$(\text{ocircle}(A)\times \text{ocircle}(B)\to C)$  $=(\text{ocircle}(A)\to (\text{ocircle}(B)\to C))$  
$=(\text{ocircle}(A)\to (B\to C))$  
$=(A\to (B\to C))$  
$=(A\times B\to C)$ 
using the universal properties of $\text{ocircle}(B)$ and $\text{ocircle}(A)$, along with the fact that $B\to C$ is in ¶since $C$ is. It is straightforward to verify that this equivalence is given by composing with ${\eta}_{A}\times {\eta}_{B}$, as needed. ∎
It may seem odd that every reflective subcategory of types is automatically an exponential ideal, with a productpreserving reflector. However, this is also the case classically in the category^{} of sets, for the same reasons. It’s just that this fact is not usually remarked on, since the classical category of sets—in contrast to the category of homotopy types^{}—does not have many interesting reflective subcategories.
Two basic properties of $n$types are not shared by general reflective subuniverses: \autorefthm:ntypessigma (closure under $\mathrm{\Sigma}$types) and \autorefthm:truncnind (truncation induction^{}). However, the analogues of these two properties are equivalent^{} to each other.
Theorem 7.7.4.
For a reflective subuniverse ¶, the following are logically equivalent.

1.
If $A:\mathrm{\P}$ and $B:A\to \mathrm{\P}$, then ${\sum}_{(x:A)}B(x)$ is in ¶.

2.
for every $A:\mathcal{U}$, type family $B:\text{ocircle}A\to \mathrm{\P}$, and map $g:{\prod}_{(a:A)}B(\eta (a))$, there exists $f:{\prod}_{(z:\text{ocircle}A)}B(z)$ such that $f(\eta (a))=g(a)$ for all $a:A$.
Proof.
Suppose 1. Then in the situation of 2, the type ${\sum}_{(z:\text{ocircle}A)}B(z)$ lies in $\mathrm{\P}$, and we have ${g}^{\prime}:A\to {\sum}_{(z:\text{ocircle}A)}B(z)$ defined by ${g}^{\prime}(a):\equiv (\eta (a),g(a))$. Thus, we have ${\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({g}^{\prime}):\text{ocircle}A\to {\sum}_{(z:\text{ocircle}A)}B(z)$ such that ${\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({g}^{\prime})(\eta (a))=(\eta (a),g(a))$.
Now consider the functions ${\mathrm{\U0001d5c9\U0001d5cb}}_{2}\circ {\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({g}^{\prime}):\text{ocircle}A\to \text{ocircle}A$ and ${\mathrm{\U0001d5c2\U0001d5bd}}_{\text{ocircle}A}$. By assumption^{}, these become equal when precomposed with $\eta $. Thus, by the universal property of $\text{ocircle}$, they are equal already, i.e. we have ${p}_{z}:{\mathrm{\U0001d5c9\U0001d5cb}}_{2}({\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({g}^{\prime})(z))=z$ for all $z$. Now we can define $f(z):\equiv p_{z}{}_{*}\left({\mathrm{\U0001d5c9\U0001d5cb}}_{2}({\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({g}^{\prime})(z))\right),$ and the second component of ${\mathrm{\U0001d5cb\U0001d5be\U0001d5bc}}_{\text{ocircle}}({g}^{\prime})(\eta (a))=(\eta (a),g(a))$ yields $f(\eta (a))=g(a)$.
Conversely, suppose 2, and that $A:\mathrm{\P}$ and $B:A\to \mathrm{\P}$. Let $h$ be the composite
$$\text{ocircle}\left(\sum _{x:A}B(x)\right)\stackrel{\text{ocircle}({\mathrm{\U0001d5c9\U0001d5cb}}_{1})}{\to}\text{ocircle}A\stackrel{{({\eta}_{A})}^{1}}{\to}A.$$ 
Then for $z:{\sum}_{(x:A)}B(x)$ we have
$h(\eta (z))$  $={\eta}^{1}(\text{ocircle}({\mathrm{\U0001d5c9\U0001d5cb}}_{1})(\eta (z)))$  
$={\eta}^{1}(\eta ({\mathrm{\U0001d5c9\U0001d5cb}}_{1}(z)))$  
$={\mathrm{\U0001d5c9\U0001d5cb}}_{1}(z).$ 
Denote this path by ${p}_{z}$. Now if we define $C:\text{ocircle}({\sum}_{(x:A)}B(x))\to \mathcal{U}$ by $C(w):\equiv B(h(w))$, we have
$$g:\equiv \lambda z.p_{z}{}_{*}\left({\mathrm{\U0001d5c9\U0001d5cb}}_{2}(z)\right):\prod _{z:{\sum}_{(x:A)}B(x)}C(\eta (z)).$$ 
Thus, the assumption yields $f:{\prod}_{(w:\text{ocircle}({\sum}_{(x:A)}B(x)))}C(w)$ such that $f(\eta (z))=g(z)$. Together, $h$ and $f$ give a function $k:\text{ocircle}({\sum}_{(x:A)}B(x))\to {\sum}_{(x:A)}B(x)$ defined by $k(w):\equiv (h(w),f(w))$, while ${p}_{z}$ and the equality $f(\eta (z))=g(z)$ show that $k$ is a retraction of ${\eta}_{{\sum}_{(x:A)}B(x)}$. Therefore, ${\sum}_{(x:A)}B(x)$ is in ¶. ∎
Note the similarity to the discussion in \autorefsec:htpyinductive. The universal property of the reflector of a reflective subuniverse is like a recursion principle with its uniqueness property, while \autorefthm:modalchar2 is like the corresponding induction principle. Unlike in \autorefsec:htpyinductive, the two are not equivalent here, because of the restriction^{} that we can only eliminate into types that lie in $\mathrm{\P}$. Condition 1 of \autorefthm:modalchar is what fixes the disconnect.
Unsurprisingly, of course, if we have the induction principle, then we can derive the recursion principle. We can also derive its uniqueness property, as long as we allow ourselves to eliminate into path types. This suggests the following definition. Note that any reflective subuniverse can be characterized by the operation $\text{ocircle}:\mathcal{U}\to \mathcal{U}$ and the functions ${\eta}_{A}:A\to \text{ocircle}A$, since we have $P(A)=\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}({\eta}_{A})$.
Definition 7.7.5.
A modality is an operation $\text{ocircle}\mathrm{:}\mathrm{U}\mathrm{\to}\mathrm{U}$ for which there are

1.
functions ${\eta}_{A}^{\text{ocircle}}:A\to \text{ocircle}(A)$ for every type $A$.

2.
for every $A:\mathcal{U}$ and every type family $B:\text{ocircle}(A)\to \mathcal{U}$, a function
$${\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{\text{ocircle}}:\left(\prod _{a:A}\text{ocircle}(B({\eta}_{A}^{\text{ocircle}}(a)))\right)\to \prod _{z:\text{ocircle}(A)}\text{ocircle}(B(z)).$$ 
3.
A path ${\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{\text{ocircle}}(f)({\eta}_{A}^{\text{ocircle}}(a))=f(a)$ for each $f:{\prod}_{(a:A)}\text{ocircle}(B({\eta}_{A}^{\text{ocircle}}(a)))$.

4.
For any $z,{z}^{\prime}:\text{ocircle}(A)$, the function ${\eta}_{z={z}^{\prime}}^{\text{ocircle}}:(z={z}^{\prime})\to \text{ocircle}(z={z}^{\prime})$ is an equivalence.
We say that $A$ is modal for $\text{ocircle}$ if ${\eta}_{A}^{\text{ocircle}}\mathrm{:}A\mathrm{\to}\text{ocircle}\mathit{}\mathrm{(}A\mathrm{)}$ is an equivalence, and we write
$${\mathcal{U}}_{\text{ocircle}}:\equiv \text{setof}X:\mathcal{U}X\mathit{\text{is}}\text{ocircle}\mathit{\text{modal}}$$  (7.7.5) 
for the type of modal types.
Conditions 2 and 3 are very similar to \autorefthm:modalchar2, but phrased using $\text{ocircle}B(z)$ rather than assuming $B$ to be valued in $\mathrm{\P}$. This allows us to state the condition purely in terms of the operation $\text{ocircle}$, rather than requiring the predicate $P:\mathcal{U}\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$ to be given in advance. (It is not entirely satisfactory, since we still have to refer to $P$ notsosubtly in clause 4. We do not know whether 4 follows from 1–3.) However, the strongerlooking property of \autorefthm:modalchar2 follows from \autorefdefn:modality2 and 3, since for any $C:\text{ocircle}A\to {\mathcal{U}}_{\text{ocircle}}$ we have $C(z)\simeq \text{ocircle}C(z)$, and we can pass back across this equivalence.
As with other induction principles, this implies a universal property.
Theorem 7.7.7.
Let $A$ be a type and let $B\mathrm{:}\text{ocircle}\mathit{}\mathrm{(}A\mathrm{)}\mathrm{\to}{\mathrm{U}}_{\text{ocircle}}$. Then the function
$$(\mathit{\text{\u2013}}\circ {\eta}_{A}^{\text{ocircle}}):\left(\prod _{z:\text{ocircle}(A)}B(z)\right)\to \left(\prod _{a:A}B({\eta}_{A}^{\text{ocircle}}(a))\right)$$ 
is an equivalence.
Proof.
By definition, the operation ${\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{\text{ocircle}}$ is a right inverse^{} to $(\text{\u2013}\circ {\eta}_{A}^{\text{ocircle}})$. Thus, we only need to find a homotopy^{}
$$\prod _{z:\text{ocircle}(A)}s(z)={\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{\text{ocircle}}(s\circ {\eta}_{A}^{\text{ocircle}})(z)$$ 
for each $s:{\prod}_{(z:\text{ocircle}(A))}B(z)$, exhibiting it as a left inverse as well. By assumption, each $B(z)$ is modal, and hence each type $s(z)={R}_{X}^{\text{ocircle}}(s\circ {\eta}_{A}^{\text{ocircle}})(z)$ is also modal. Thus, it suffices to find a function of type
$$\prod _{a:A}s({\eta}_{A}^{\text{ocircle}}(a))={\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{\text{ocircle}}(s\circ {\eta}_{A}^{\text{ocircle}})({\eta}_{A}^{\text{ocircle}}(a)).$$ 
which follows from \autorefdefn:modality3. ∎
In particular, for every type $A$ and every modal type $B$, we have an equivalence $(\text{ocircle}A\to B)\simeq (A\to B)$.
Corollary 7.7.8.
For any modality $\text{ocircle}$, the $\text{ocircle}$modal types form a reflective subuniverse satisfying the equivalent conditions of \autorefthm:modalchar.
Thus, modalities can be identified with reflective subuniverses closed under $\mathrm{\Sigma}$types. The name modality comes, of course, from modal logic, which studies logic where we can form statements such as “possibly $A$” (usually written $\diamond A$) or “necessarily $A$” (usually written $\mathrm{\square}A$). The symbol $\text{ocircle}$ is somewhat common for an arbitrary modal operator. Under the propositionsastypes principle, a modality in the sense of modal logic corresponds to an operation on types, and \autorefdefn:modality seems a reasonable candidate for how such an operation should be defined. (More precisely, we should perhaps call these idempotent^{}, monadic modalities; see the Notes.) As mentioned in \autorefsubsec:whentrunc, we may in general use adverbs to speak informally about such modalities, such as “merely” for the propositional truncation and “purely” for the identity^{} modality (i.e. the one defined by $\text{ocircle}A:\equiv A$).
For any modality $\text{ocircle}$, we define a map $f:A\to B$ to be $\text{ocircle}$connected if $\text{ocircle}({\mathrm{\U0001d5bf\U0001d5c2\U0001d5bb}}_{f}(b))$ is contractible^{} for all $b:B$, and to be $\text{ocircle}$truncated if ${\mathrm{\U0001d5bf\U0001d5c2\U0001d5bb}}_{f}(b)$ is modal for all $b:B$. All of the theory of \autorefsec:connectivity,\autorefsec:imagefactorization which doesn’t involve relating $n$types for different values of $n$ applies verbatim in this generality. In particular, we have an orthogonal factorization system.
An important class of modalities which does not include the $n$truncations is the left exact modalities: those for which the functor $\text{ocircle}$ preserves pullbacks as well as finite products. These are a categorification of “LawvereTierney topologies” in elementary topos theory, and correspond in highercategorical semantics to sub$(\mathrm{\infty},1)$toposes. However, this is beyond the scope of this book.
Some particular examples of modalities other than $n$truncation can be found in the exercises.
Title  7.7 Modalities 

\metatable 