|
|
|
|
|
by crashandburn4
4422 days ago
|
|
Am I misunderstanding this? reading all the examples, the difference between recursion and corecursion seems to be equivalent to the difference between tail recursion and stack recursion. Is that right? can anyone post an example of corecursion that is stack recursion? or is there something else that needs to happen to qualify something as corecursion? |
|
To get a brief feel for the difference consider the "type function":
where 1 is the type with only one value and the type (X + Y) is the tagged union of types X and Y. We might decide to talk about the type "iterated T" as the type If we tag "left" values with Inl and "right" values with Inr and take * to be the only value of type 1, then values of IT look like which looks a lot like the Peano Naturals. Now, a recursive definition on IT looks like and a corecursive definition looks like In other words, recursion occurs by constantly pulling "layers" of type T off of values of IT while corecursion occurs by adding "layers" of type T on to seed values to build an IT.We can convert IT to natural numbers by using cata
and we can invert that conversion with ana and we can build the "infinite" structure omega with ana