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 expression in open #7140

Closed
vicuna opened this issue Feb 8, 2016 · 3 comments
Closed

module expression in open #7140

vicuna opened this issue Feb 8, 2016 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Feb 8, 2016

Original bug ID: 7140
Reporter: @Drup
Status: feedback (set by @damiendoligez on 2016-02-25T13:47:04Z)
Resolution: open
Priority: normal
Severity: feature
Target version: later
Category: typing
Monitored by: @Drup @diml @yallop @hcarty

Bug description

Currently, the various form of open only accept a longident ("Foo.Bar"). Even longident-with-application ("Foo(Bar).Baz") is refused by parsing.

This means that locally opening a functor application or an unpacked module is a bit verbose (let module M = ... in let open M in ).

Could it be possible to have a module expression there ? At the very least as a shortcut for what I wrote earlier.

I realize there is going to be a grammar issue with the short syntax for local open, but keeping the short local open restricted feels ok to me.

@vicuna
Copy link
Author

vicuna commented Feb 9, 2016

Comment author: @lpw25

There are four kinds of module expression which are not allowed in open, and
each with good reason:

  • struct ... end does not work because it's components don't have valid
    paths. A module must have a name before you can refer to its components.

  • (Foo : S) does not work for similar reasons. : is an opaque ascription
    operator -- (Foo : S).t does not equal Foo.t -- so its components are
    unnamed. It can't just be treated as transparent ascription in open
    statements because the inner modules would also need to be transparently
    ascribed. In the future, there will probably be a proper transparent
    ascription operator (:>?) which can be used in both opens and module
    aliases.

  • Foo(Bar) would have two possible meanings:

    • Execute Foo(Bar) and open the resulting module.
    • Make the type-level components of Foo(Bar) avaiable in the current scope.

    The first option involves performing side effects during open, whereas
    open should be purely a compile-time operation on scopes. This is similar
    to why Foo(Bar).t is a valid path but Foo(Bar).v is not (t for type, v
    for value). It would also perpetuate the incorrect assumption of many OCaml
    beginners: that functors are compile-time magic and there is only one
    Foo(Bar) module.

    The second option is semantically fine, but would probably cause confusion as
    people might expect the value components to also be in scope.

  • functor (..) -> ... cannot be used to create a structure without
    application.

@vicuna
Copy link
Author

vicuna commented Mar 22, 2018

Comment author: runhang

Cf. #1506

@vicuna vicuna added the typing label Mar 14, 2019
@nojb
Copy link
Contributor

nojb commented Mar 16, 2019

PR merged #2147, closing.

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