Mutual recursion is a case in computer science where multiple problems that depend on each other form a cycle, like the chicken and egg problem.
Questions tagged [mutual-recursion]
104 questions
2
votes
2 answers
C++ mutual template dependency?
I'd like to have two structures which point to eachother. Specifically, I'd like to have the following:
template
class MyStructure {
public:
typedef map>> MapType;
…

Federico Lebrón
- 1,772
- 1
- 11
- 10
2
votes
3 answers
Resolve circular C++ template dependency
Suppose I have:
template
class A {
typedef T t_type;
void done_work();
};
template
class B {
typedef T t_type;
void do_work(){
// adds work to an asynchronous event queue, eventually T.done_work() is called
…

Andrew Hundt
- 2,551
- 2
- 32
- 64
2
votes
1 answer
Clarification of Haskell mutual recursion
I've come across these discussions of mutual recursion, initially in the context of the let expression, i.e., a let allows for bindings to refer to one another with no mind for order. (See here.) I then saw this discussion in Wikipedia. This gives…

147pm
- 2,137
- 18
- 28
2
votes
1 answer
how to make HTML from a list in scheme, racket
This is a very long question ... I am new and joined, so please don't attack me. Apologies for my bad communications in English. I have some defintions:
An HTML(H) is one of
Str
Tag
A Tag is
(cons Sym (listof H))
I want to use mutual…

Capis_O
- 21
- 2
2
votes
1 answer
How can I define a decreases for mutually recursive functions in Dafny?
In the "Draft Dafny Reference Manual" 4.0.2 it describes defining decreases clauses for mutually recursive functions but where the variables decreasing in both functions are of the type nat. I have tried to do the same thing but it has not…

david streader
- 589
- 2
- 7
2
votes
2 answers
Declaring interdependent values and functions in Standard ML
How do you define functions and values depending on each other in Standard ML?
The following program:
val cmds = [("help", cmd_help)];
fun cmd_help () = List.app (fn cmd => print (#1 cmd ^ "\n")) cmds;
cmd_help ();
Does not compile:
$ mlton…

Lassi
- 3,522
- 3
- 22
- 34
2
votes
1 answer
Mutually recursive functions over product type
(Beginner Coq question)
Related to Defining recursive function over product type, I'm trying to define a recursive function over a product type. The difference here is there's a mutually recursive definition. I keep running into this…

Felipe
- 3,003
- 2
- 26
- 44
2
votes
1 answer
Implementation of `first` in Arrow library
I don't understand the implementation of first in the library.
first seems to be defined recursively with *** -- I don't see when the recursion shall end!?
first :: a b c -> a (b,d) (c,d)
first = (*** id)
and
(***) :: a b c -> a b' c' -> a (b,b')…

user3680029
- 179
- 8
2
votes
1 answer
Can I do “complex” mutual recursion in Coq without let-binding?
Consider the following pair of mutually recursive Coq data types, which represent a Forest of nonempty Trees. Each Branch of a Tree holds an extra boolean flag, which we can extract with isOK.
Inductive Forest a : Type
:= Empty : Forest a
| …

Antal Spector-Zabusky
- 36,191
- 7
- 77
- 140
2
votes
1 answer
Mutual Recursion Question
How do I change two functions that are Mutual Recursive to each other to make them into a linear recursion? Do I have to have both the methods in a single method?

Benjamin
- 85
- 1
- 10
2
votes
2 answers
Does this implementation of merge sort use mutual recursion?
Does this mergeSort algorithm use mutual recursion? I realize that mergeSort calls the merge function and it calls itself (mergeSort), but since merge does not call mergeSort is it not mutual recursion and simply just recursion?
function…

georgej
- 3,041
- 6
- 24
- 46
2
votes
3 answers
Mutually recursive evaluator in Haskell
Update: I've added an answer that describes my final solution (hint: the single Expr data type wasn't sufficient).
I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct.
This is the language:
type Var =…

Tom Lokhorst
- 13,658
- 5
- 55
- 71
2
votes
1 answer
How to create graph with cycles without mutable data using?
I have next code:
module MakeLink (Key : Map.OrderedType) = struct
module Links = Map.Make (Key)
type 'a t =
{ links : 'a t Links.t;
value : 'a
}
type key_t = Key.t
let make value =
{ links =…

Valentyn Zakharenko
- 2,710
- 1
- 21
- 47
2
votes
1 answer
ANTLR : Fixing Left Recursive and Mutually Left Recursive
This is part of a grammar I'm working on as to develop a parser tool which will be important in doing my research. It gives me an error under ANTLR IDE In eclipse saying paraction, action, cspaction are mutually left-recursive.
I've scanned the web…

Shiyam
- 71
- 5
1
vote
1 answer
How to make mutual recursion in APL?
I'm trying the following mutual recursion example in Dyalog APL Win10:
even ← { (odd ⍵-1) ∨ ⍵=0 }
odd ← { (even ⍵-1) ∧ ⍵>0 }
even 7
WS FULL
It looks like the ∨ and ∧ doesn't stop evaluation at reaching a defined state.
The WS…

Miroslav Popov
- 3,294
- 4
- 32
- 55