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

Local module opens #6363

Closed
vicuna opened this issue Apr 5, 2014 · 3 comments
Closed

Local module opens #6363

vicuna opened this issue Apr 5, 2014 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Apr 5, 2014

Original bug ID: 6363
Reporter: mkehrt
Assigned to: @lefessan
Status: closed (set by @lefessan on 2014-04-06T09:15:30Z)
Resolution: not a bug
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

I've been writing a lot of Scala recently, and on returning to OCaml, there is one feature I miss a lot. This is the ability to locally open a module inside a non-toplevel scope. In OCaml this would manifest as an "open ... in" binding used as follows:

let f x =
...bindings...
open M in
...more bindings and expressions...

This would be particularly useful when using modules to manage the namespaces of record labels, as one could open the module containing the record labels in a function dealing with that record but allow the labels to be namespaced elsewhere. This could avoid the variable.ModuleName.fieldName syntax, which is fairly cumbersome.

@vicuna
Copy link
Author

vicuna commented Apr 5, 2014

Comment author: mkehrt

Similarly, local module bindings

let f x =
module M = ModuleName in
...

I realize these are fairly large changes to the language, but I think they would be useful in a future release.

@vicuna
Copy link
Author

vicuna commented Apr 5, 2014

Comment author: @garrigue

Both of these features are available.
They are described in the language extension part of the manual.
The syntax is respectively
let open M in
and
let module M = ... in

@vicuna
Copy link
Author

vicuna commented Apr 6, 2014

Comment author: @lefessan

There is also M.{ x = .. } and M.( { x = } ) that can be used to open a module within an expression/record.

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

2 participants