Is it possible to have mutual recursive types ([<Struct>]
) spread across different files? The types are directly under a namespace.
My solution is to put them in one big file and use type ... and ... and ... etc
construction. Is it the only way?
Mutual recursion is very common in functional programming and in some problem domains, such as recursive descent parsers, where the datatypes are naturally mutually recursive.
Mutual recursion is a variation recursion. Two functions are called mutually recursive if the first function makes a recursive call to the second function and the second function, in turn, calls the first one.
You can use a technique called untying the recursive knot where you parameterize one over the other.
So this:
type a = B of b
and b = A of a
becomes:
type 'b a = B of 'b
type b = A of b a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With