We have some modules which are ml only even though they could be mlis (eg declarations)
We also have a few mli only modules (eg csig)
IIRC there were some problems with make and mli only, but we have only dune now
Shall we go back to mli only where possible?
What is the advantage of a .mli without an .ml, with respect to an .ml without an .mli?
Having both is boring, but I can't see much of a difference between the two options, other than pure .ml can declare exceptions
Just .ml
used also to behave better w.r.t. to the foo_intf.ml
pattern include
as to avoid duplication of interfaces between .ml
/ .mli
files. There are also differences about aliases, modules without implementation couldn't be aliased. So indeed I think we renamed to some .ml
not due to make problems, but due to the old API.mli
file using module alias.
This pattern is used pervasively in some of the OCaml ecosystem.
IMHO, we should discuss a bit about the different styles and options.
Enrico Tassi said:
What is the advantage of a .mli without an .ml, with respect to an .ml without an .mli?
Actually, that is a question I asked on OCaml's Discourse earlier today. If you have a .ml without .mli, OCaml complains. If you have a .mli without .ml, OCaml is happy. https://discuss.ocaml.org/t/dealing-with-warning-70-missing-mli/8542/4
The compiler is happy until you want to do something such as module F = Foo
where only foo.mli
exists.
The discussion in discuss.ocaml
is kind of incomplete; Dune has not problem with .mli
only files, the compiler has as it doesn't support the same set of features for example w.r.t. packing. So dune workarounds this limitation by automatically generating an implementation file for .mli
-only modules. I can point out to the relevant issues if anyone is interested.
Personally, I find warning 70 activated by default to be a really bogus choice.
IIRC the problem with make and .ml only files was that if you run in parallel ocaml/ocamlopt you get a race on the .cmi. But I guess dune does this right. So, what is wrong with .ml only files? (other than the warning which can be disabled globally)
I just removed 1600 lines of dead code in Why3 thanks to this warning, so I am not eager to disable it.
mli without ml ensures you don't start adding vals in the module
@Gaëtan Gilbert I agree with your remark, ml files without a corresponding mli file are footguns begging for use. Interfaces are precisely that, they are guaranteed to only contain declarations. ml-only files are the equivalent of broken C headers where you can actually create code without realizing.
IMO this whole discussion is due to a limitation of OCaml, i.e. we should be able to consider implementation-free interfaces as if they were modules as well. Or a build system feature where mli-only files are duplicated on the fly into the corresponding ml file. Shouldn't be too hard to do?
(another minor defect is that it reduces greppability. I know that only mli files should matter for declarations but that's not true if you only have an ml file. This is annoying for the stuff that used to be mli-only like kernel/declarations and similar AST-defining files)
Or a build system feature where mli-only files are duplicated on the fly into the corresponding ml file. Shouldn't be too hard to do?
That’s exactly what dune does already :)
Last updated: Dec 05 2023 at 05:01 UTC