4 ms·
In practice recursion probably covers most of the cases where it matters. Corecursion could (if awkwardly) be converted into ordinary recursion.
by im2w1l 12y ago
In practice recursion probably covers most of the cases where it matters. Corecursion could (if awkwardly) be converted into ordinary recursion.
- DanWaterworth 12y agoCorecursion doesn't mean what you think it means. You mean mutual recursion.
- waterhouse 12y ago(read this with a mild trollface) Given functions f and g, it is possible to write them as the same function M. Supply an extra argument called "mode": if 0, then the function behaves like f, and if 1, then the function behaves like g. If you want to call f or g, call M with the "mode" argument as 0 or 1 respectively. If f and g take different numbers of arguments, let M take the larger number of arguments, and when you intend to call the function that takes fewer arguments, supply 0s for the extra args. This should indeed implement mutual recursion in terms of self-recursion. The grandparent commenter did say "Corecursion could (if awkwardly) be converted into ordinary recursion", which I would say is technically correct, which some say is the best kind of correct. (Perhaps he has a somewhat less awkward scheme in mind.)
- dllthomas 12y agoYou seem to be talking about mutual recursion. http://en.wikipedia.org/wiki/Corecursion http://en.wikipedia.org/wiki/Corecursion http://en.wikipedia.org/wiki/Mutual_recursion http://en.wikipedia.org/wiki/Mutual_recursion
- dllthomas 12y agoIt occurs to me that the existence (and nature) of "coroutines" probably primes this mistake.
- jules 12y agoIt doesn't. Most of the advantage of tail calls over loops comes exactly from the fact that they work for all tail calls not just direct recursive calls. Examples: loops with a non-trivial iteration structure, programming in CPS, programming with monads, and doing state machines.
- current_call 12y agoNo, it doesn't. Think about composition and partial application.