Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to current module in OCaml

Tags:

ocaml

Is there any kind of keyword, like this, to refere to a current module? For example, what should I put in gap here:

module Test: Test_Type =
struct

    module N = Test_Outside(___);;

end;;

Where Test_Outside is another module parameterized by Test_Type.

like image 328
Nutel Avatar asked Dec 17 '10 22:12

Nutel


1 Answers

No, there is not, but it's strange you need to.

You may be able to do weird tricks with recursive modules (an extension to the base language), but most likely the problem is in the way you formulate things, and you actually don't need such self-reference.

See the manual for recursive modules

In my experience, going the recursive route is always gonna be a problem in the end. You should rather take the time to simplify your design and break any dependency cycle by using a more layered approach. For example, here you want N to be defined in Test and at the same time to refer to Test. But does the Test_Outside module need to know about N and other parts of Test using N, or does it rather only use the "base" definitions of Test, that are "before N" ? You may use two separate "Test" modules, with the second extending the first :

module Test_Outside(Test : Small_Test_Type) = struct ... end

module InnerTest : Small_Test_Type = struct ... end

module Test : Test_type = struct
   include InnerTest
   module N = Test_Outside(InnerTest)
   ...
end
like image 125
gasche Avatar answered Nov 20 '22 23:11

gasche