When you define
type foo = int
type bar = Leaf | Node of int * int
there is a fundamental difference between foo
, which is a type synonym for a type that already existed (int
), and bar
that introduces a new type, introducing new constructors Leaf
and Node
, and is distinct from all the previous ones.
When you write
module M = struct
type foo = int
type bar = Leaf | Node of int * int
end
the type M.foo
is equal to int
, but the type M.bar
is only equal to itself: it is new and has nothing existing to compare to (even a type with the exact same constructors would be considered different and incompatible).
It makes sense to publish, in a signature, the fact that M.foo = int
, but not to say that M.bar = Leaf | ...
: M.bar
is only equal to itself, M.bar
, and the signature refinement M with type bar = M.bar
would not give you any information.
The problem in your code is that you insist on using an ascription to the signature tGraphe
that uses abstract types. You gain nothing by writing jrouquie's code
type global_arc = Vide | Node of (int*int)
module Two : tGraphe with type noeud = int and type arc = global_arc = struct
type noeud = int
type arc = global_arc
end;;
instead of simply
module Two = struct
type noeud = int
type arc = Vide |Node of(int*int)
end
The construction M : S
is not a check only. It will actively hide typing information from M
. The construction S with type ... = ...
is there to allow to hide a bit less than you would with S
. But if you want to hide nothing at all, in your example, just don't use a signature ascription! Just write module M = struct ... end
.
If you only use : S
to check that you were not wrong, didn't make any mistake in fields names and stuff, you can use it on the side as a pure check:
module Two = struct ... end
let () = ignore (module Two : S) (* only a check! *)
SML has a distinction between "transparent" module annotations that only check compatibility, and "opaque" module annotations (generally called sealing), that enforce compatibility and hide type information. OCaml only has the opaque sealing ones, so you have to be careful not to over-use it.
PS: when asking a question on StackOverflow, it would be better if your code was written in english than in french.