I have a Map module that I want to be in scope within a class. How do I open that module within the entire class?
This was my guess, but it was wrong:
module My_map = struct
module Map = ...
end
class my_object =
object
open My_map.Map
method ...
end
But this isn't working. Is there a way to open the module at the class level and not within each method?
Specifically, the issue that I'm having is this:
module Data = My_map.Map.Make(String)
However, when I try to access functions (within the class) that I added to My_map.Map.Make, I get compiler errors saying they don't exist.
I looked through the OCaml grammar just now and I don't see a place to open a module for a class definition as a whole.
You can say something like
So it might make sense to be able to say:
However the grammar doesn't allow it.
You can open the module globally, or maybe give it a short synonym that's less onerous to type in your class definition.
Update
Rereading your question, I can't shake the feeling that you think you need to open a module in order to use its symbols. This isn't true, opening a module is just for convenience. Any symbol that could be accessed by opening a module can also be accessed without opening the module, by using a full module path. In fact many (including myself) would tell you to avoid opening modules in all but a very few cases.
If you're just having trouble specifying the right module path, it would help a lot if you could give self-contained (smallish) code that demonstrates the problem.