summaryrefslogtreecommitdiff
path: root/sec
diff options
context:
space:
mode:
authorChloe Brown <chloe.brown.00@outlook.com>2025-06-25 18:04:07 +0100
committerChloe Brown <chloe.brown.00@outlook.com>2025-06-25 18:04:07 +0100
commit84cd0255d021e5bfe0f9bd1680143287f06ba95f (patch)
tree4471b48b9d3ec0a75725a1f23216ce0ed9598692 /sec
parent50351a6bf34fa7e4980c9dfda7364a61e756e78c (diff)
Move list operations later.
Diffstat (limited to 'sec')
-rw-r--r--sec/encoding.ltx40
1 files changed, 20 insertions, 20 deletions
diff --git a/sec/encoding.ltx b/sec/encoding.ltx
index 23a8784..9b905bc 100644
--- a/sec/encoding.ltx
+++ b/sec/encoding.ltx
@@ -72,26 +72,6 @@ operator satisfies the following equation:
\dofold{\roll*~t~u}{x}{v} \coloneq \sub{v}{x/\mapkw{}~(\lambda i. \dofold{\mathsf{index}~t~i}{x}{v})~u}
\]
-We require a few operations on lists to compute this transformation:
-\begin{description}
- \item[\(\mathsf{nil}\)] the empty list;
- \item[\(\mathsf{cons}\)] adds an element to the head of a list;
- \item[\(\mathsf{snoc}\)] adds an element to the tail of a list;
- \item[\(\mathsf{length}\)] computes the number of elements in a
- list; and
- \item[\(\mathsf{index}\)] retrieves a value from a list by position.
-\end{description}
-
-We give the equations these operators satisfy below.
-\begin{align*}
-\mathsf{snoc}~\mathsf{nil}~v &= \mathsf{cons}~v~\mathsf{nil} &
-\mathsf{snoc}~(\mathsf{cons}~t~u)~v &= \mathsf{cons}~t~(\mathsf{snoc}~u~v) \\
-\mathsf{length}~\mathsf{nil} &= \zero &
-\mathsf{length}~(\mathsf{cons}~t~u) &= \suc~(\mathsf{length}~u) \\
-\mathsf{index}~(\mathsf{cons}~t~u)~\zero &= t &
-\mathsf{index}~(\mathsf{cons}~t~u)~(\suc~n) &= \mathsf{index}~u~n
-\end{align*}
-
To encode \roll{} into \roll*{} we require a function that traverses a
value of type \(\sub{A}{X/\mu X. A}\) and collects all inductive
components into a single list. We can extend a list with a single
@@ -117,6 +97,26 @@ that calls each accumulator within \(A\) in sequence. The definition
is by induction on the well-formedness derivation of \(A\). The
details of the definition are in \cref{M-sec:distrib}.
+We require a few operations on lists to compute this transformation:
+\begin{description}
+ \item[\(\mathsf{nil}\)] the empty list;
+ \item[\(\mathsf{cons}\)] adds an element to the head of a list;
+ \item[\(\mathsf{snoc}\)] adds an element to the tail of a list;
+ \item[\(\mathsf{length}\)] computes the number of elements in a
+ list; and
+ \item[\(\mathsf{index}\)] retrieves a value from a list by position.
+\end{description}
+
+We give the equations these operators satisfy below.
+\begin{align*}
+\mathsf{snoc}~\mathsf{nil}~v &= \mathsf{cons}~v~\mathsf{nil} &
+\mathsf{snoc}~(\mathsf{cons}~t~u)~v &= \mathsf{cons}~t~(\mathsf{snoc}~u~v) \\
+\mathsf{length}~\mathsf{nil} &= \zero &
+\mathsf{length}~(\mathsf{cons}~t~u) &= \suc~(\mathsf{length}~u) \\
+\mathsf{index}~(\mathsf{cons}~t~u)~\zero &= t &
+\mathsf{index}~(\mathsf{cons}~t~u)~(\suc~n) &= \mathsf{index}~u~n
+\end{align*}
+
At the end of this phase, the \systemtinline{compose} example is
unchanged. The \systemtinline{balanced} example reduces to the below
code. Notice how the \suc{} branch uses the same variable