Diff of module interfaces

module

#1

Hi all,

is there a tool that can compute a diff of module interfaces?

Use case, I have modules M.A and N.A and I want to see how their interfaces differ.

Thanks!
E.


#2

I’m not aware of any tools to do this directly, but you can get the information interactively from the toplevel/utop by taking advantage of type errors.

First, some modules to compare:

utop # module L1 = struct type t1 let f1 x = assert false end;;
module L1 : sig type t1 val f1 : 'a -> 'b end

utop # module L2 = struct type t2 let f1 x = assert false let f2 x = assert false end;;
module L2 : sig type t2 val f1 : 'a -> 'b val f2 : 'a -> 'b end

Next, compare each module against the other’s signature:

utop # module Check : module type of L1 = L2;;
Error: Signature mismatch:
  Modules do not match:
    sig type t2 = L2.t2 val f1 : 'a -> 'b val f2 : 'a -> 'b end
  is not included in
    sig type t1 val f1 : 'a -> 'b end
  The type `t1' is required but not provided

utop # module Check : module type of L2 = L1;;
Error: Signature mismatch:
  Modules do not match:
    sig type t1 = L1.t1 val f1 : 'a -> 'b end
  is not included in
    sig type t2 val f1 : 'a -> 'b val f2 : 'a -> 'b end
  The value `f2' is required but not provided
  The type `t2' is required but not provided

This shows which fields are missing from L2 vs L1 and which are missing from L1 vs L2.