# [MLton] Mlton style question concerning modules

**Jesper Louis Andersen
**
jlouis@mongers.org

*Wed, 25 Aug 2004 23:47:08 +0200*

The style guide specifies that signatures should be independent of the
implementation. I liked it so much I chose to use it for my own project
this time. But - I ran into a problem which I sketch below:
A graph is represented by both a (triangular) bit matrix and a
array/list structure. I have:
signature GRAPH_ARRAY_STRUCTS =
sig
structure Vertex: VERTEX
end
signature GRAPH_ARRAY =
sig
type t
(* ... various uses of Vertex.t *)
end
GRAPH_MATRIX_STRUCTS and GRAPH_MATRIX are similiar.
I drive these 2 structures in parallel, using a joining
Graph structure to query the representation giving the
best running time:
signature GRAPH_STRUCTS =
sig
structure Vertex: VERTEX
end
signature GRAPH =
sig
type t
(* ... various uses of Vertex.t *)
end
Now, I have:
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. I do not want to
put them into the GRAPH_STRUCTS signature, since they are
local to the Graph structure.
How is this accomplished in a neat way? The best thing I
can think of now is something along the lines of:
structure Graphs:
sig
structure GraphArray:> GRAPH_ARRAY
structrue GraphMatrix:> GRAPH_MATRIX
sharing GraphArray.Vertex = GraphMatrix.Vertex
end =
struct
structure GraphArray = GraphArray(structure Vertex = Vertex)
strucutre GraphMatrix = GrapmMatrix(strucutre Vertex = Vertex)
end
and then put this inside the Graph structure and refer to these
now identifiers. But I would like to ask what the MLton style is.
--
j.