-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.mli only modules #9
Comments
Properly supporting .mli could only work for unwrapped libraries since you can't alias a module without implementation, so I'm not sure it's worth doing. Moreover I heard an argument in the past that .mli only modules are not a good idea (/cc @sliquister). However, to make porting easier, I added a hack to automatically copy the .mli to the .ml in such cases, with a warning. |
The argument against .mli only file is simple:
I'll also point out copying the .ml to a .mli doesn't work for the case where the .mli contains: module F(X : ..) : sig module type S = .. end and some other file uses F(X).S or F(X).t (which doesn't create a dependency on the implementation), which I have seen people use. |
Thanks for the details. I've updated the warning message to point to this discussion |
For what it's worth, I disagree strongly, and I find
Not for documentation purposes. Documentations is better hosted in an
That's my choice, isn't it? :) |
(Note that I agree with the problem of aliasing modules with no implementation ... but I still consider that a bug in the compiler ....) |
Drup raises a good point here about installation. If we're unable to have .mli modules, is there a way to mark an analogous .ml file to be installed? |
@rgrinberg I'm pretty sure it's what jbuilder does already |
This seems to come up often, so I think something could be done about it. Currently .mli only modules work by chance. The facts that you cannot alias them and that if you write It'd be different if they where properly supported by the compiler. I think we need two things:
If someone is willing to work on this, I'm happy to add proper support for them in jbuilder |
Just for info, porting opam itself to use jbuilder, I hit an instance of this little heuristic not working in src/format/opamTypes.mli which includes the line |
Maybe a better heuristic would be to generate: module rec Foo : sig
<contents of the mli>
end = Foo
include FOo |
Who'd have thought recursive modules could get into something so superficially simple! It'd certainly be handy for it to work automagically I'm not sure where I stand on not being allowed to use (or strongly discouraged from using) .mli files solely for collecting types together (it's done extensively in opam, but in many ways I find it quite irritating) - it'll certainly be easier to adopt in this instance if jbuilder can work without needing to adapt the .mli file from day 1. |
The problem with this solution is that if you write |
Might it be possible (if dirty) to make the shim only available in the |
I haven't double-checked, but I think I hit a related problem with this in #104 - if you're using an external library where there's a .cmi file only, this creates a dependency on a non-existent module which prevents using |
This is weird, what do you mean by creating a dependency? jbuilder will only pass .cmxa files when linking, so I can't see how this could happen. Except of course if in the external library the .cmi only module wasn't really a pure interface, which enforces the idea that mli only modules are a bad idea :p Anyway, I added a stanza |
@diml - here I think is a minimal and correct example. So I have a third-party library consisting of two files type t = A and let foo = LibTypes.A and that's been compiled using Now I have a library that's part of my project which also includes two files type u = B
include module type of struct include LibTypes end and let foo = LibTypes.A
let bar = ProgTypes.B Now, without jbuilder that's compiled using I can now make a toplevel with these: So far, so good. Now, let's convert proglib.cma to be built using jbuider. type u = B
include LibTypes and jbuilder now includes module
at this point, in order to build this with jbuilder, I'm forced to vendor the third-party library too. That's not fixed using the recursive module trick either. |
I see, can you try the |
That seems to be working - I think I must have set something up incorrectly in my previous test with the recursive module trick. Thanks! |
Does the |
No - see fd76d7b. |
See, for example, here for the current workaround |
Thanks. I saw the workaround but I was wondering why it wasn't the default behaviour ? (without a warning I mean) |
Jbuilder is opinionated 😄 With jbuilder automatically handling link commands (i.e. never having to having to specify the module name for a types-only module in a Makefile list), this doesn't bother me for new projects. I agree for legacy libraries it's a nuisance, but I also agree it's better to wait until there's proper compiler support for .mli-only modules |
The recursive module hack doesn't work in general. With tyxml's xml_sigs, the compiler gives you:
|
When porting cohttp to jbuilder, I discovered that .mli only modules don't seem to work. Since ocamlbuild supports them, it would be great if jbuilder would as well.
The text was updated successfully, but these errors were encountered: