Hi,
I’m trying to “extend” a set of recursive modules by adding functions to them
while keeping equalities between types. With the code below, the compiler gives me this error:
15 | type t = Orig.X.t = Y of Y.t | Z
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type Orig.X.t
Constructors do not match:
Y of Orig.Y.t
is not compatible with:
Y of Y.t
The types are not equal.
module Orig = struct
module rec X : sig
type t = Y of Y.t | Z
end =
X
and Y : sig
type item = A | B
type t = item list
end =
Y
end
module rec X : sig
type t = Orig.X.t = Y of Y.t | Z
end = struct
type t = Orig.X.t = Y of Y.t | Z
end
and Y : sig
type item = Orig.Y.item = A | B
type t = item list
end = struct
type item = Orig.Y.item = A | B
type t = item list
end
The error disappear if don’t use recursive modules. Of course, in my real code, the types really are mutually recursive.
Is this a limitation due to recursive modules ?
module Y : sig
type item = Orig.Y.item = A | B
type t = item list
end = struct
type item = Orig.Y.item = A | B
type t = item list
end
module X : sig
type t = Orig.X.t = Y of Y.t | Z
end = struct
type t = Orig.X.t = Y of Y.t | Z
end
The reason I have such code is because I want to apply a deriving PPX only while testing, to avoid having a dependency on a PPX.
I’m trying to use a combination of three PPXes: ppx_gen_rec, ppx_import and ppx_deriving.show.
The code above is the output of them, my code looks like this:
module%gen rec X : sig
type t = [%import: Orig.X.t] [@@deriving show]
end =
X
and Y : sig
type item = [%import: Orig.Y.item] [@@deriving show]
type t = [%import: Orig.Y.t] [@@deriving show]
end =
Y
Suggestions about this problem are welcome too 