Suppose we have a set $S$ of constants of the Simply-Typed Lambda Calculus (STLC) various types, and the operation of union $\cup$ which takes two constants and forms their union.
For example, $S$ could be $\{\, a_e, b_e, f_{e \to t}, g_{e \to e \to t}\}$, where $e$ and $t$ are ground types of the STLC and $e \to t$ is a function type. We can then form $\{a, g, b \}$, by unioning $a$, $g$ and $b$. We could do this iteratively, first unioning $g$ and $b$, and thence $a$.
However, suppose we wanted to do this sort of iterative process in the STLC with ordered pairs, forming $(g, b)$ and then $(a, g, b)$. One way might be to use the Kuratowski encoding of ordered pairs, and use union as before, as well as a singleton-forming operation $\zeta$. We would therefore add to the STLC $\zeta$ and $\cup$. In the Kuratowski encoding, $(a, g, b)$ is defined as $(a, (g, b))$, which in turn is defined as $\{ \{a \}, \{ \{g \}, \{g, b \} \} \}$.
Take $\{ \{g \}, \{g, b \} \}$. We could form this by applying $\zeta$ to $g$ and $\zeta$ to $b$ and then unioning $\{g\}$ and $\{b \}$ to form $\{g, b \}$, applying $\zeta$ to the result to form $\{ \{g,b \} \}$ and then applying $\zeta$ twice to $g$, and unioning $\{ \{ g \}\}$ and $\{ \{g,b \} \}$, to form $\{ \{g \}, \{g, b \} \}$. Then a function of the following kind could be written:
$$\lambda b, a. \zeta \, \zeta \,\zeta\, a \,\cup \,\zeta\,(\zeta\,\zeta\, g \cup \zeta\,(\zeta \,g\cup \zeta\,b)))$$
Another way would be to use the powerset monad, where
- the unit $\eta$ of the monad takes an element and forms a singleton
- the join of the monad $\mu_A : \mathcal{P}(\mathcal{P}(A)) \to \mathcal{P}(A)$ is union, i.e., $\mu_A(S) = \bigcup_{B \in S} B$.
For $M \in \mathcal{P}(A)$ and $K : A \to \mathcal{P}(B)$ we have $$M \star K = \bigcup_{x \in M} K(x) = \mu_A(\{K(x) \mid x \in M\})$$
We can compute the union of two subsets $X, Y \subseteq S$ as \begin{multline*} \{\mathbf{false}, \mathbf{true}\} \star (\lambda b : \mathbf{bool} \,.\, \mathbf{if}\,b\,\mathbf{then}\,X\,\mathbf{else}\,Y) \\ = \bigcup \{\mathbf{if}\,b\,\mathbf{then}\,X\,\mathbf{else}\,Y \mid b \in \{\mathbf{false}, \mathbf{true}\} \} = \bigcup \{X, Y\} = X \cup Y. \end{multline*}
We could then form (a, g, b), by applying the $\bigstar$ iteratively, to create the Kuratowski encoding of $(a, g, b)$.
However, both these constructions have to go through the laborious detour of forming a set which, by the Kuratowski encoding, constitutes an ordered pair.
I am looking for a monad or applicative which allows us to form tuples such as $(a, g, b )$ in a more direct way than the ways just described, or simply in an alternative way.