Le 15 juin 05 à 17:39, Remi Vanicat a écrit : > 2005/6/15, Damien Bobillot : > >> I'm defining a graph structure compatible with the ocamlgraph >> library. >> >> I want to be able to access all neighbors and edge to neighbors of a >> vertex in 0(1), so I think I need to store the outgoing edge list of >> each vertex in the vertex structure. I also need to be able to access >> the source and destination of an edge in 0(1), so I store these >> vertex in the edge structure. >> >> A standard Caml will be : >> >> type vertex = { >> label : int; >> out_edges : edge list; >> ... >> } and edge = { >> label : int; >> src : vertex; >> dst : vertex; >> ... >> } >> >> However, in ocamlgraph, the vertex and edge type must be defined by >> modules of signatures (and I cannot modify it) : >> >> module type VERTEX = sig >> type t >> type label >> val create : label -> t >> val label : t -> label >> end >> module type EDGE = sig >> type t >> type label >> type vertex >> val create : vertex -> label -> vertex -> t >> val label : t -> label >> val src : t -> vertex >> val dst : t -> vertex >> end >> > > [...] > > >> It works fine, but it doesn't respond to my problem : I want that V >> use a type from E and at the same time E use a type of V. > > Why don't you do something like what follow ? > > type vertex = { > label : int; > out_edges : edge list; > ... > } and edge = { > label : int; > src : vertex; > dst : vertex; > ... > } > > module MyVertex : (VERTEX with t=vertex and label=int)= > struct > type t=vertex > .... > end > > module MyEdge : (EDGE with t=edge ...) = > struct > type t = edge > .... > end > > It should work with no problem. Yes, it works !!! Modules are powerful, but as every powerful things, it's hard to use without a manual... (and I didn't found a good manual on the web, if you know one I'll be interested). Thank you very much -- Damien Bobillot