-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Simplify the typing of module aliases #6063
Comments
Comment author: @garrigue OK, I was maybe a bit too ambitious. |
Comment author: @lpw25 This feature seems fine, but I wonder if it wouldn't be better to provide a proper module alias statement (I have seen "open A.B.C as M" suggested before). Unlike "module M = A.B.C" it would not add a generate a field in the signature, and unlike "let module M = A.B.C in" it would not have a runtime cost. I think this is probably what most people want when they write something like "module M = A.B.C" anyway. This could work with class definitions, so that the example from the caml-list would be: class z = let open String as A in object end;; |
Comment author: @garrigue In the case of "let module", you should actually be able to type more programs with this new interpretation of let-module, so this is an improvement, with the same advantages as a special "open" syntax (while being more general), and without the need for new syntax. For normal modules, this is another story. |
Comment author: @lpw25 Just to clarify, are you saying that this proposal will allow the following to type-check: let f (sm : 'a Map.Make(String).t) = and will avoid the current runtime cost of local module aliases: http://janestreet.github.io/ocaml-perf-notes.html#local-module-definitions-are-not-free If so, then I agree that a local "open .. as .." statement is unnecessary. As you say, things are more complicated for normal modules. |
Comment author: @garrigue Yes, this is what I mean. At first I thought that it would apply immediately to paths containing functor applications too. |
Comment author: @alainfrisch Is there a natural formalization of the proposed change, or would the resulting system mimics the implementation (one special rule for the case where the let-bound module is a path)? |
Comment author: @garrigue Merged the module-alias branch to trunk at revision 14394. |
Comment author: @garrigue The name of the option is now -no-alias-deps, rather than -trans-mod, which was rather cryptic. Note that one part of the description is not done yet: allowing a restricted for of let module in classes. |
Original bug ID: 6063
Reporter: @garrigue
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:27:39Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 4.02.0+dev
Fixed in version: 4.02.0+dev
Category: typing
Related to: #4166
Monitored by: pcouderc @gasche @ygrek @hcarty @yakobowski
Bug description
Currently, constructs such as
module M = A.B.C
or
let module M = A.B.C in ...
have a high type-checking cost: a new module is created and added to the environment, which requires typing A.B.C and strenghtening; moreover, in the case of let module, one has to ensure that types from M do no escape (i.e. expand them to A.B.C.t).
It would be much simpler to use the same code as for open, just adding aliases to the environment.
As a result there would be no need to check anything, and this construct could be allowed in class definitions for instance. This would change the printing of types in normal mode, but if you use the -short-paths option, you would still get the benefit of abbreviations when printing types.
In theory this is OK to do that even if the type contains applications (but only to paths).
I believe this is 100% backwards compatible, but this may need some check for the case where some .cmi disappears. The behavior of type checking in presence of dangling paths is not completely specified.
The text was updated successfully, but these errors were encountered: