Shalom, code17.
c> Have no idea about your efficiency problem, but recursive module
c> seems like a heavy-weight solution for me. I will only take this
c> approach if there is some reason making it considerably elegant
c> than other solutions.
Can you describe your situation, where recursive modules was
heavy-weight for you?
>> type my_struct =
>> { ...
>> ; current_state : mutable state_t
>> }
>> and state_t =
>> { ... some references to my_struct ... }
>> }
>> ;
>>
>> Everything looks good, but I want to create and modify
>> values of type state_t only inside one small module.
>> Can this be done using something like "private"?
>> (type state_t is represented by record).
c> Yes, this is exactly the private type. Prefix the "private" keyword
c> to the definition of state_t in the signature will do it.
I have a more complex structure, so I can't declare type my_struct
inside module State (which should be the only module that able to
create/modify state_t). Something like this:
type my_struct = ...;
module SomeBigModule1 = ... it uses my_struct ...;
module SomeBigModule2 = ... it uses my_struct and SomeBigModule1;
module State = ... here I want to declare private type state_t.
... this module uses my_struct, SomeBigModule1
... and SomeBigModule2;
module SomeBigModule3 = ... uses my_struct, SomeBigModule1,
... SomeBigModule2 and module State;
If I declare private type state_t together with type my_struct,
I won't be able to create/modify values of this type inside
module State. And I can't move module State before BigModules1
and 2 because module State uses them.
So, I see these solutions:
1. create module MyStruct for type my_struct and declare modules
MyStruct, SomeBigModule1, SomeBigModule2 and State as recursive
modules.
2. use parametrized type (my_struct_gen 's) and specify
type of state after module State:
"type my_struct = my_struct_gen State.t".
3. declare types together, but state_t won't be private.
I don't know the cost of solution #1. I approximately know
the cost of solution #2 (operations on field
"my_struct.current_state" will be generic, since the exact
type of this field is unknown to functions that work with
"my_struct_gen 's"; not a very big penalty really).
So, if recursive modules have the same performance as usual
modules (my original question was exactly about it), I will
use solution #1, otherwise I will use #2.
--
WBR,
dmitry mailto: gds-mlsts%40moldavcable.com">gds-mlsts
moldavcable.com
.