Interesting.
Isn’t it already the case while we don’t write the types/values in a resi file to make them public?
How would be the behavior with resi file ? Does the behavior will change or it only concern the lonely res file situation ?
For migration, we could phase it in by copying the unambiguous modules idea from John-David Dalton. For major version X, if there’s an export keyword in the file, only the things marked as exported are exported. Otherwise, everything is exported.
For major version X + 1, only the things marked as exported are exported - regardless of the export keyword.
Beautiful! The only thing that is not clear is how it’s going to work with .resi. I assume that if there is a mismatch in res and resi, it would be a compiler error?
That would be awesome! Yes please! This is something that I miss from typescript. As someone wrote in this forum, it is far easier to remember to explicitly make public methods to expose than to make them private.
If something is exported, that something should be imported at some point. But we don’t import, we open instead or use fully-qualified module paths. So, cross-module communication is misaligned with JS already and pub alone doesn’t make ReScript further from JS significantly.
Private by default (backed by an efficient implementation) would be a really nice thing. It aligns with what we’re used to in JS. Exposing it as a flag and then eventually (if things go well) making it the default behaviour is a sensible approach to me. (Given tooling to help migrate codebases.)
I agree with @kevanstannard on the naming. pub is trending in other languages, but it might not be the best fit from a design perspective.
This is great. I am currently tinkering with Rust and just yesterday I thought I’d really prefer private-by-default in ReScript as well and now you are suggesting exactly that.
I’m also curious about how this would work, and if it could completely replace resi files. For example, would you be able to implement code like this without an interface?
// Even.res
type t = int
let make = i =>
if mod(i, 2) == 0 {
Some(i)
} else {
None
}
let toInt = i => i
// Even.resi
type t
let make: int => option<t>
let toInt: t => int
@Hongbo do you have a spec of how this is going to work under the hood?
And do the compiler changes impact the general performance of projects without .resi files? Or do you still need .resi files for that?
This is not in conflict with resi files, you can still add resi. The compilation of resi is independent from res file, it is like a filter for existing res files