Skip to content
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

module rename X = Y. #4961

Closed
vicuna opened this issue Jan 15, 2010 · 5 comments
Closed

module rename X = Y. #4961

vicuna opened this issue Jan 15, 2010 · 5 comments

Comments

@vicuna
Copy link

vicuna commented Jan 15, 2010

Original bug ID: 4961
Reporter: yziquel
Status: closed (set by @mshinwell on 2016-12-12T16:06:16Z)
Resolution: won't fix
Priority: normal
Severity: feature
Version: 3.11.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: yziquel mehdi @glondu @hcarty

Bug description

Hi. it would be nice to have a "module rename X = Y" feature. For instance, I have two Postgresql modules. One provided by the postgresql-ocaml package, and another one in my local code. I would like to write "module rename PGconv = Postgresql" so that the local Postgresql module is now refered as PGConv, and such that it frees the namespace in order to be able to refer to the Postgresql module of postgresql-ocaml as Postgresql.

Such a feature would be quite useful, as managing module name conflicts is rather painful in OCaml.

@vicuna
Copy link
Author

vicuna commented Jan 19, 2010

Comment author: yziquel

Perhaps an "open X as Y" syntax would be more convenient.

In the same spirit, it would be nice to have the following code being valid

type t
module X = struct
type t
let f : t -> .t = blah blah blah...
end

where .t would represent the type t outside of X, i.e. the first 'type t' declaration.

@vicuna
Copy link
Author

vicuna commented Feb 26, 2010

Comment author: goswin

If you have 2 modules with the same name then it already is unclear, at least to the casual reader, which of the two you are refering too.

As to the suggestion of "open X as Y" that would still leave X (both of them) in the namespace. At least I would expect that. So I would expect X.foo and Y.foo to now be the same. The shadowed other X would still be unaccessable. The "rename X as Y" would make it clearer that it removes X from the namespace and X.foo would be invalid or not Y.foo.

I feel that "open X as Y" can be written as "module Y = X".

And for your type shadowing problem you can use the following (confusing) syntax:

module X = struct type parent_t = t type t let f : t -> parent_t = fun t -> Obj.magic 0 end;;

module X : sig type parent_t = t type t val f : t -> parent_t end

MfG
Goswin

@vicuna
Copy link
Author

vicuna commented Feb 28, 2010

Comment author: yziquel

I really want one module name to disappear.

Suppose you've got two modules A and B.A.

What I want is to write

rename A as C
open B

so that you have module C (the former A module) and module A (the former B.A) module.

More generally, it is somewhat surprising that modules, which are rather semantic in nature, are so tightly coupled with their names, which is a syntactic concept. I am not saying that the approach I proposed is the right one, but it would be nice to be able to have a more efficient way to manage module name clashes in OCaml.

As for the second problem, of type shadowing, the problem is indeed that you can only deal with this rather natural problem by using a confusing syntax. The code proposed by Goswin would look terrible in a .mli file with ocamldoc called upon it. Hence my suggestion of .t for the type in the parent module.

@vicuna
Copy link
Author

vicuna commented Mar 1, 2010

Comment author: goswin

As long as the initial module names are distinct you can rename them to your liking. The original name won't disapear but that doesn't matter if you do it in the right order.

module C = A
module A = B.A (* or open B in this case *)

In other cases you might have to create a dummy name first to get the order right.

module T123 = A
module A = B
module B = T123

An actual rename you would only need when you have for example a module named Buffer and now you want to access the stdlibs Buffer. Or rather when someone else duplicates a module name and you have to work with that code.

MfG
Goswin

@vicuna
Copy link
Author

vicuna commented Dec 12, 2016

Comment author: @mshinwell

The problem seems to be the use of libraries that are not packed or namespaced in some way. It is very unlikely that the renaming of modules in the manner suggested will ever be implemented---however, there are possible solutions involving the use of module aliases; and further improved namespacing support is likely to appear in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant