mutual-recursion

[F#] How to have two methods calling each other?

I'm a bit confused as to how to get two method to call each other (i.e., have A() call B() and B() call A()). It seems that F# only 'sees' the method after it's been encountered in code, so if it hasn't, it just says value or constructor has not been defined. Am I missing something very basic here? ...

How does one resolve F# Type Reference Errors?

I've been through my books, and I've googled until I've ran out of search terms, yet I still can't find an example or answer to this problem: The following code does not compile because the type Effect and the type Affect have not been declared at the time Entity is declared. So what I don't understand is how do to work around this. I...

F# forward type declarations

Hello everybody, I stumbled across this problem in F#. Suppose, I want to declare two types that reference each other: type firstType = | T1 of secondType //................ type secondType = | T1 of firstType //................ How do I do that, so the compiler does not generate an error? ...

What is this kind of mutual "recursion" called?

My issue is with a certain style of code that very much resembles recursion, but isn't quite that. Recursion is, to quote Wikipedia, "a method of defining functions in which the function being defined is applied within its own definition". Similarly mutual recursion applies another function which, directly or indirectly, applies the func...

What is the standard way to optimise mutual recursion in F#/Scala?

These languages do not support mutually recursive functions optimization 'natively', so I guess it must be trampoline or.. heh.. rewriting as a loop) Do I miss something? UPDATE: It seems that I did lie about FSharp, but I just didn't see an example of mutual tail-calls while googling ...

Problem determining how to order F# types due to circular references

I have some types that extend a common type, and these are my models. I then have DAO types for each model type for CRUD operations. I now have a need for a function that will allow me to find an id given any model type, so I created a new type for some miscellaneous functions. The problem is that I don't know how to order these types...

Can discriminated unions refer to each other?

I'm building an expression tree using discriminated unions. The below code: type IntExpression = | TrueIsOne of BoolExpression type BoolExpression = | LessThan of IntExpression * IntExpression | And of BoolExpression * BoolExpression | Or of BoolExpression * BoolExpression | Bool of bool throws an error because Bo...

Mutually recursive classes

How do I implement mutually recursive classes in C++? Something like: /* * Recursion.h * */ #ifndef RECURSION_H_ #define RECURSION_H_ class Class1 { Class2* Class2_ptr; public: void Class1_method() { //... (*Class2_ptr).Class2_method(); //... } }; class Class2 { Class1* Class1_ptr; public: void C...

Mutually recursive evaluator in Haskell

I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct. This is the language: type Var = String type Binds = [(Var, Expr)] data Expr = Var Var | Lam Var Expr | App Expr Expr | Con Int | Sub Expr Expr | If Expr Expr Expr | Let Var Expr Ex...

F#: Mutually recursive functions

Possible Duplicate: [F#] How to have two methods calling each other? Hello all, I Have a scenario where I have two functions that would benefit from being mutually recursive but I'm not really sure how to do this in F# My scenario is not as simple as the following code, but I'd like to get something similar to compile: let ...

How can I reorder these F# functions to make sense?

I thought I'd be getting along alright with F# since I'm decent at Haskell, but I feel like I'm being stumped by dead simple issues. I have some parsing code for a simple JSON parser, like this: let rec parseObject tokens = function | '"' :: cs -> parseString tokens cs | ':' :: cs -> parseValue tokens cs | '}' :: cs -> tokens, cs ....

Is it possible to define types that depend on each other and are defined in separated files?

I am trying to implement a library with extended parsing capabilities. I decided that I will use fsyacc because I knew it from the university. Unfortunately I encountered following problem. I defined a class for the head of my grammar (Head) and place its implementation in a single file. Then I defined parser as: ... %start head %type...