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

open_as would be convenient #3652

Closed
vicuna opened this issue Sep 10, 2002 · 2 comments
Closed

open_as would be convenient #3652

vicuna opened this issue Sep 10, 2002 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Sep 10, 2002

Original bug ID: 1381
Reporter: administrator
Status: closed (set by @damiendoligez on 2016-12-02T14:14:44Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 4.02.0
Category: ~DO NOT USE (was: OCaml general)
Related to: #3653

Bug description

Here's a wish list item.

I don't like to use open. If I encounter code like

open An_excellent_module
open A_good_module
open A_mediocre_module
let _ = f ()

I might have to search all three modules to discover where f is
defined. In .ml files, a simple fix is to omit the open statements
and have:

let _ = A_good_module.f ()

That tends to get wordy, so I often do this instead:

module G = A_good_module
let _ = G.f ()

This is brief and unambiguous, and it works well.

In signatures, this doesn't work. I can say

val x: A_good_module.t

but there's no easy way I know of to abbreviate it down to

val x: G.t

Certainly saying "module G = A_good_module" in a signature doesn't
work. I've tried a number of workarounds, but none that I liked. The
one I'm using now noticeably slows down the compiler and makes
ocamlbrowser nearly useless, for instance.

Thus, I'd like to have a new type of open. The syntax in a signature
might be:

open A_good_module as G

or perhaps

open G = A_good_module

After you do this, the declaration:

val x: G.t

would be exactly equivalent to having

val x: A_good_module.t

in the signature.

If you're willing to seriously consider accepting a patch for this,
let me know and I might try to produce one. I don't want to produce a
patch without such an expression of interest because the previous two
ocaml patches I proposed (bugs 1289 and 1341) have not received a reply.

Tim Freeman
tim@fungible.com
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D 7180 76DF FE00 34B1 5C78

@vicuna
Copy link
Author

vicuna commented Sep 13, 2002

Comment author: administrator

This is not an answer to your main question, but just about ocamlbrowser:

Certainly saying "module G = A_good_module" in a signature doesn't
work. I've tried a number of workarounds, but none that I liked. The
one I'm using now noticeably slows down the compiler and makes
ocamlbrowser nearly useless, for instance.

Supposing that your method is the one used in #3653, I would suggest you name
the file differently from the module it contains.

ConsciousImpl.ml:
module type Conscious = sig ... end
module Conscious : Conscious = struct .. end

If you use the same name, ocamlbrowser is unable to see that a reference
to Conscious inside module Conscious is about the file Conscious, because
it has already opened Conscious in the environment (needed for type
definitions...)
So you could say this is an ocamlbrowser bug, but naming two modules identically
doesn't seem to be a very good idea.

For the compiler speed, I believe I know the workaround, but must convince
Xavier first...

Cheers,

Jacques

@vicuna
Copy link
Author

vicuna commented Dec 2, 2016

Comment author: @damiendoligez

Since module aliases were introduced in 4.02.0, you can write in a signature:

module G = A_good_module
val x : G.t

I think this fully resolves the question.

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