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
Keep equation on module type while strengthening #6333
Comments
Comment author: @garrigue There is the same problem as with module aliases: since type information is not duplicated, a new dependence on the source is introduced. compiled with: This would not work anymore, and I do not even see a workaround (we are already using include here). If we really see module types as having a nominal aspect, the correct thing to do would rather be to add a separate "manifest" field, just like for type definitions. |
Comment author: @alainfrisch Do you think it is going to be a problem in practice? If the user deliberately wants to hide a.cmi when compiling c.ml, he could accept the burden of creating a proper b.mli which expands the definition for S. And one could also argue that keeping a symbolic reference to A.S reduces the size of b.cmi, which is nice. Otherwise, would it be possible to expand module type aliases only while saving the signature? And yes, a solution based on a more structural comparison of package types would probably be a nicer approach to fixing this. |
Comment author: @garrigue I just uploaded a patch that does the "right thing". module type S = sig type u type t end;; (* ok to convert between structurally equal signatures, and parameters (* with subtyping it is also ok to forget some types ) (* but you cannot forget values (no physical coercions) ) |
Comment author: @garrigue By the way, there remains another question: whether to allow using first class modules without defining a module type in advance. |
Comment author: @garrigue Structural comparison of first class module types merged into trunk at revision 14450. |
Original bug ID: 6333
Reporter: @alainfrisch
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:27:04Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.02.0+dev
Fixed in version: 4.02.0+dev
Category: typing
Tags: patch
Related to: #6159
Monitored by: @yallop @yakobowski
Bug description
I suggest to modify the strengthening of module type bindings in signatures in order to keep the equation to the original module type (as we currently do for abstract module types). Concretely, one would change in Mtype.strengthen_sig:
| Sig_modtype(id, decl) :: rem ->
let newdecl =
match decl.mtd_type with
None ->
{decl with mtd_type = Some(Mty_ident(Pdot(p, Ident.name id, nopos)))}
| Some _ ->
decl
in
...
into:
| Sig_modtype(id, decl) :: rem ->
let newdecl =
{decl with mtd_type = Some(Mty_ident(Pdot(p, Ident.name id, nopos)))}
in
...
This changes makes sense, since module type now have a nominal aspect, because of first-class modules.
Several examples of code which would benefit from the change have been posted on the caml-list ("First class modules aliases" thread, Feb. 2014).
Would there be any drawback from this change?
File attachments
The text was updated successfully, but these errors were encountered: