I am wondering if there is a way to rename a type in a module signature.
It can be done with destructive substitution if the type is an abstract one:
module type S = sig
type t (* needs to be renamed *)
(* some type's and val's that use type t *)
end
module type S' = sig
type renamed
include S with type t := renamed
end
This gives a new module type, S’, that is like S but naming it’s type renamed
instead of t
…
… But unfortunately this approach fails, or at least, becomes very cumbersome, when t depends on other types, for example:
module type S = sig
type r
type s = r -> r
type t (* needs to be renamed *) = s * s
end
module type S' = sig
(* here we also have to do a destructive substitution for types t depends on! *)
type r
type s = r -> r
type renamed = s * s
include S
with type r := r
and type s := s
and type t := renamed
end
Here, to use destructive substitution, we have to also replace types that are used to define t!
Is there a more elegant way, that does not needs you to redefine all the types the one you want to rename depends on?