Reference to current module in 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
mod开发者_JAVA技巧ule N = Test_Outside(___);;
end;;
Where Test_Outside is another module parameterized by Test_Type.
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
精彩评论