- Hi,

I've got a problem using the ocamlgraph library (but this is not related

exactly to the library). In my graph, The nodes must store a "pointer" to

some of their edges. So I need to use (I think) recursive module as the

edge type is only known ofter applying the functor which creates the graph

module.

But I have a unification problem, shown below :

-----------------------------------------------

module Edge = struct

type t = unit

let compare = compare

let default = ()

end

module rec Node : sig

(* Process.E.t is not Edge.t *)

type t = { mutable edge_aux: Process.E.t }

end = struct

type t = { mutable edge_aux: Process.E.t }

end

and Process : Graph.Sig.G with type V.label = Node.t and type E.label =

Edge.t = struct

include Graph.Persistent.Digraph.AbstractLabeled(Node)(Edge)

let add_aux node =

let e = E.create node () node in

let p = V.label node in

p.Node.edge_aux <- e

(* the error is here: ^ *)

end

-----------------------------------------------

~$ ocamlc -I `ocamlc -where`/ocamlgraph graph.cma a.ml

File "a.ml", line 32, characters 31-32:

This expression has type

E.t = Graph.Persistent.Digraph.AbstractLabeled(Node)(Edge).E.t

but is here used with type Process.E.t

-----------------------------------------------

What I do not understand is that the type E.t is made abstract in Process

by the signature constraint but E.t in Process should still be Process.E.t

from outside of the module, or am I doing something wrong ?

The output module of the functor AbstractLabeled is documented there :

http://ocamlgraph.lri.fr/doc/Persistent.S.AbstractLabeled.html

Thank you for your answers,

Mathias - Hello,

2010/5/6 Mathias Kende <mathias@...>:> I've got a problem using the ocamlgraph library (but this is not related

In your example, add_aux is not directly involved in the recursion, so

> exactly to the library). In my graph, The nodes must store a "pointer" to

> some of their edges. So I need to use (I think) recursive module as the

> edge type is only known ofter applying the functor which creates the graph

> module.

that you can get away with an auxiliary module like this:

module Edge = struct

type t = unit

let compare = compare

let default = ()

end

module rec Node : sig

(* Process.E.t is not Edge.t *)

type t = { mutable edge_aux: Process_aux.E.t }

end = struct

type t = { mutable edge_aux: Process_aux.E.t }

end

and Process_aux : Graph.Sig.G with type V.label = Node.t and type

E.label = Edge.t

= Graph.Persistent.Digraph.AbstractLabeled(Node)(Edge)

module Process =

struct

include Process_aux

let add_aux node =

let e = E.create node () node in

let p = V.label node in

p.Node.edge_aux <- e

end

Of course, this solution will not work in more complicated settings in

which add_aux would be a genuine part of

the recursion.

--

E tutto per oggi, a la prossima volta

Virgile