Modules, Signatures, Functors And Making Them Fit Together
<p>I have a simple question about modules and getting them to accommodate signatures and functors. Should we, if we have the opportunity, make the modules fit the functor or should we make the functor fit the modules? I know it depends on what you can modify but what if you are writing the modules, signatures, and functors. I think this will make sense with a small example. Say I have two modules which are/can be 'signature' wise identical except for one function.  </p>

<pre><code>module One =(*this module has a immutable data container*)
struct
...
(* container-&gt;string-&gt;container *)
let add_str_container cont str = ...
...
end
</code></pre>

<p>and</p>

<pre><code>module Two =(*this module has a mutable data container*)
struct
...
(* container-&gt;string-&gt;unit *)
let add_str_container cont str = ...
...
end
</code></pre>

<p>Now I can fix this dilemma by creating a new function and hiding the fact that one module's add_str_container returns unit and the other returns container.</p>

<pre><code>module One =(*this module has a immutable data container*)
struct
...
(* container-&gt;string-&gt;container *)
let add_str_container cont str = ...(* now this is not exported in the signature *)
(* container-&gt;string-&gt;container *)
let add_str_aux cont str = add_str_container cont str

...
end
module Two =(*this module has a mutable data container*)
struct
...
(* container-&gt;string-&gt;unit *)
let add_str_container cont str = ...(* now this is not exported in the signature *)
(* container-&gt;string-&gt;container *)
let add_str_aux cont str = add_str_container cont str; cont

...
end
</code></pre>

<p>The addition of add_str_aux and the omission of add_str_container solves the type problem nicely and everything is type correct and simple in the signature and functor. My question is basically - How do you get modules which may contain immutable and mutable containers to a unique signature when mutable containers generally return unit on updates and immutable containers return a new reference to the updated container?</p>