Reason: proposal: remove open or reduce open usage in reason syntax

Created on 16 Aug 2017  路  7Comments  路  Source: reasonml/reason

namespace support is coming soon. One thing I worried is that people tend to use open more and more which makes it more challenging for tools like ocamldep to track it.

So I propose that if we can remove global open (can still keep local open) but introduce some sugars for qualified import.

for example, (feel free to invent more firendly syntax)

#use {PkgA.M0, PkgB.M1, Pkg.M2}
which is equivalent to

module M0 = PkgA.M0
module M1  = PkgB.M1
module M2 = Pkg.M2
#use  {PkgA.M0(fib,fib2)}



md5-7d3fa19cd29ee1c4fcb6df37978da9ea



let fib = PkgA.M0.fib
let fib2 = PkgB.M1.fib

The goal is to remove global open(which is also a source of bugs) but introduce reasonable sugar

Parser RFC

Most helpful comment

I've explored this a bit w/ https://github.com/jaredly/ppx_import
We could take advantage of javascipt's familiarity with:

import {thing} from Pkg
import {SubModule, thing, Some: {withinSome}, name: renamed} from Source

All 7 comments

I've explored this a bit w/ https://github.com/jaredly/ppx_import
We could take advantage of javascipt's familiarity with:

import {thing} from Pkg
import {SubModule, thing, Some: {withinSome}, name: renamed} from Source

Another alternative syntax, closer to haskell/purescript's:

import Pkg (thing)
import Source (SubModule, thing, Some (withinSome), name (renamed))

I _love_ the semantics of this proposal. I vastly prefer explicit import and default namespacing to the way open works atm.

  • Does this take us further away from legal OCaml code towards BS specific instructions?
  • Will that make it harder to consume code from OCaml?
  • And if we remove global open, what will happen to library code that uses it?

Does this take us further away from legal OCaml code towards BS specific instructions?

No, my proposal is valid OCaml, it is just a subset of OCaml(less liberal)

I think this is a great idea. I personally perfer the js syntax but something similar to elm or haskell would work aswell.

No, my proposal is valid OCaml, it is just a subset of OCaml(less liberal)

But if it's a subset, doesn't that mean that it won't work with ordinary OCaml code? i.e. I won't be able to take an OCaml lib, and use it easily from BS without converting it manually?

Hi, is there any progress/plan regarding the issue? What docs say at the moment is:

Use open this sparingly, it's convenient, but makes it hard to know where some values come from.

The currently suggested approach is to open the modules locally. While better than doing so globally, I would argue that it still suffers the hard to know where some values come from issue. Some support along the lines of the proposal would be really nice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ondrejsevcik picture ondrejsevcik  路  3Comments

bluddy picture bluddy  路  3Comments

modlfo picture modlfo  路  4Comments

chenglou picture chenglou  路  3Comments

TrakBit picture TrakBit  路  3Comments