I am writing a rather small pde-solving application in FORTRAN and I am trying to use OOP. Now, I have several modules, some of them define types with corresponding internal procedures.
Now the problem is what do I do if one module operates with a type defined within another module and the later model also operates with the type of the former? I give an example.
Say, I have two modules, one defines a type Mesh, the other one a type NodeVariable. Now I want each NodeVariable to be associated with the mesh it is going to be solved on, so I add a type(Mesh) :: mesh field in the type’s definition. So far it is no problem I can write use module-mesh to get access to the definition of type mesh. But I also want the mesh to be aware of the variables defined on it so I declare type(NodeVariable), allocatable :: var(:) as a field and add a procedure to add variables to the mesh on the fly. But now I am stuck, because I cannot afford another use statement: it causes the module to use itself and thus everything crashes. Solution?
Consider your modules connected by use statements into a graph. Fortran forbids cycles in this graph, as you have discovered. The solution is to re-design your graph to avoid cycles.
In your case you could simply define both types in the same module.