I'd like to clarify one point: currently it seems to me that triple signature duplication is necessary while declaring a functor, provided we export it in the .mli file. Here is an example:
Suppose we have a functor Make, which produces a module A parametrized by SigA (simplest example I could think of). Consequently, in the .mli file we have:
module type A = sig
type a
val identity : a -> a
end
module type SigA = sig
type a
end
module Make (MA:SigA) :
A with type a := MA.a
Now I understand that we have to write an implementation in the .ml file:
module Make (MA:SigA) = struct
type a = MA.a
let identity obj = obj
end
So far so good, right? No! Turns out we have to copy the declaration of A and SigA verbatim into the .ml file:
module type A = sig
type a
val identity : a -> a
end
module type SigA = sig
type a
end
module Make (MA:SigA) = struct
type a = MA.a
let identity obj = obj
end
While I (vaguely) understand the rationale behind copying SigA (after all, it is mentioned in the source code), copying A definition seems like a completely pointless exercise to me.
I've had a brief look through the Core codebase, and they just seem to either duplicate it for small modules and for larger once they export it to the separate .mli, which is used both from .ml and .mli.
So is it just a state of affairs? Is everyone fine with copying the module signature THREE times (once in the .mli file, two times in the .ml file: declaration and the definition!!) Currently I'm considering just ditching .mli files altogether and restricting the modules export using signatures in the .ml files.
EDIT: yes I know that I can avoid this problem by declaring the interface for A inline inside Make in the .mli file. However this doesn't help me if I want to use that interface from outside of that module.
module type ofconstruct. The very problem you describe used to plague the Frama-C source code as long as it was maintaing compatibility with OCaml < 3.12, but now that Frama-C has switched to 3.12.1 or higher, the source code is greatly simplified by the use of this feature. - Pascal Cuoqsig .. end, and then for the users of the module obtain the signature by usingmodule type of Make(...). I've had a (very brief) look at the Frama-C codebase --- it seems that they define functors "inline" mostly. However such an approach makes it impossible to obtain a signature for an abstract, non-parametrized module type (though I'm not sure whether it is a good thing) - George Karpenkovmodule type ofhelps here, other than perhaps removing the nested module type name in the separate file solution (though what I'm thinking of is rather a hack I wouldn't recommend). - Andreas Rossberg