nLab
corecursion
Corecursion exploits the existence of a morphism from a coalgebra for an endofunctor to a terminal coalgebra for the same endofunctor to define an operation. It is dual to recursion?. See also coinduction.
Examples
- For the endofunctor on Set, the terminal coalgebra is , the extended natural number system. Define a function :
add(n, m) =
\begin{cases}
(n - 1, m) & if\; n \gt 0; \\
(0, m - 1) & if\; n = 0,\; m \gt 0; \\
* & if\; m = n = 0.
\end{cases}
This makes into an -coalgebra. The unique arrow to the terminal coalgebra defines addition on the natural numbers extended with .
Reference