syntax icon indicating copy to clipboard operation
syntax copied to clipboard

First class support for private toplevel items

Open bobzhang opened this issue 4 years ago • 10 comments

private let u = 3
private let {length} = module (List)
private external ..

Note private in expression is not needed

let u = {
  let a = b  // a is already private by the scope
}

bobzhang avatar Mar 03 '21 04:03 bobzhang

When the OCaml version is upgraded this is already supported using:

open {
   let u = 3
   ...
}

Are you aware of that?

jfrolich avatar Mar 03 '21 04:03 jfrolich

Is it planned for modules too?

private module Styles = {
  // css in js declarations
}

would be pretty nice to have to detect dead code without needing an interface file sometimes

bloodyowl avatar Mar 03 '21 07:03 bloodyowl

Is it planned for modules too?

private module Styles = {
  // css in js declarations
}

would be pretty nice to have to detect dead code without needing an interface file sometimes

This is also covered with the local open feature.

jfrolich avatar Mar 03 '21 08:03 jfrolich

This is also covered with the local open feature.

I feel like the DX would be better for beginners to have a private X vs open { X } though 🙂

bloodyowl avatar Mar 03 '21 08:03 bloodyowl

private would actually be a desugaring of that new inline open

chenglou avatar Mar 03 '21 09:03 chenglou

Note I proposed private let instead of let private since it looks like the former is easier to implement

bobzhang avatar Mar 04 '21 04:03 bobzhang

Just a minor thing: did you consider the possibility of using a slightly shorter keyword, something like pvt? I imagine that in some contexts private could be used often, creating some sort of grammar noise. A shorter keyword would improve the situation. On the other hand, a private block would make this change unnecessary:

private {
    let u = 3
    let {length} = module (List)
    external ..
}

dodomorandi avatar Mar 04 '21 07:03 dodomorandi

private is already a keyword used in other places

bobzhang avatar Mar 04 '21 12:03 bobzhang

private is already a keyword, so we'll reuse it. Won't create a new one. pvt is short but not that descriptive. (Old Reason syntax used pri for "private" in some places. Folks didn't like it)

private block won't do; you need to interleave some private and non-private lines, so that'll end up being lots of bulky blocks for one-line bindings.

chenglou avatar Mar 04 '21 16:03 chenglou

Currently unsure if this topic is colliding with this RFC regarding private by default.

For backlog grooming reasons, we'll remove the PRIORITY:high tag for now.

ryyppy avatar May 02 '22 17:05 ryyppy

The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.

stale[bot] avatar May 28 '23 19:05 stale[bot]