# [MLton] Mlton style question concerning modules

**Stephen Weeks
**
MLton@mlton.org

*Wed, 25 Aug 2004 15:06:42 -0700*

>* functor GraphArray (S: GRAPH_ARRAY_STRUCTS):> GRAPH_ARRAY = ...
*>* functor GraphMatrix (S: GRAPH_MATRIX_STRUCTS):> GRAPH_MATRIX = ...
*>*
*>* and
*>*
*>* functor Graph(S: GRAPH_STRUCTS):> GRAPH =
*>* struct
*>*
*>* open S
*>*
*>* structure GraphArray = GraphArray(structure Vertex = Vertex)
*>* structure GraphMatrix = GraphMatrix(structure Vertex = Vertex)
*>*
*>* (* ... *)
*>*
*>* end
*>*
*>* but this obviously doesn't work since the Array and Matrix
*>* representations need to have a sharing constraint so the
*>* Vertex structure is shared amongst them.
*
The problem is that the :> on functors Graph{Array,Matrix} has hidden
the vertex type. With the MLton style, :> often isn't useful for
functor results, because of this problem. You could explicitly
propagate the sharing, as in
functor GraphArray (S: GRAPH_ARRAY_STRUCTS)
:> GRAPH_ARRAY where type Vertex.t = S.Vertex.t
But this rapidly becomes unwieldy. So, the MLton style is to *not*
use :> on functor results, unless you intend for the functor to be
generative (see examples from the MLton lib, like UniqueId) or you are
willing to manually propagate the sharing (e.g. UnorderedSet).
Not using :> is OK because the MLton style is fully functorized, the
functors are closed, and functor arguments are already treated like :>
for the purposes of type checking a functor body.