I'm trying to understand what the categorical definition of (co)recursion means. Here's the relevant excerpt from nLab:
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.
I have a vague idea of what corecursion is in the programming sense (in the way Wikipedia describes it).
I understand some basics of category theory at a level that alows me to understand the meaning of the sentences a monad is a monoid in the category of endofunctors and the tensor product $V\otimes U$ is an initial arrow among all bilinear maps from $V\times U$, but I still have a hard time deciphering the above.
That is, I understand all words there, but not how to interpret them.
I will rephrase the question about regular (coco) recursion, because I already have a better understanding there in the algorithmic sense, and because I hope that going to category language will be easier there, expecting that reversing the arrows afterwards will magically make me understand the dual, too.
In particular, I would like to understand:
- the role of the endofunctor $F$
- the role of the algebra $FX\to X$ (or the coalgebra $X\to FX$)
- the role of the initial (terminal) one among the latter
- how all of these corespond to my current understanding of recursion (e.g. in the sense of trees or recurrent number sequences).
The nLab article has an example, but sadly I do not find it very illuminating. It states e.g. that $\bar{\mathbb N}$ is terminal for $X\to 1+X$ and that "+" is derived from some (to me, weirdly defined) function "add", but I do not understand where these facts came from, and even if I take them for granted, I still can't easily answer the 4 questions. I also expect to be able to apply the same reasoning for regular recursion and "recover" it from the category language, but this example doesn't help me with that. I also read through the two cited references and even though helpful, they didn't lead me to a clear-cut answer to 1-4.
Actually in the dual article for recursion, some insight is found in a paragraph therein that I overlooked when I first formulated this question. Still, it is not as complete, and since then I developed a clearer picture that I'd like to share in a self answer.