How about open with multiple params? Like 'open Js , Js.String2, Belt'?

One of the problems I see (not an expert but have some trouble with visual clutter) in FP is the constant repetition of module names and the risk of shadowing other names when opening them.
So, I’m starting to use ‘open’ only in the precise scope but the multiple lines bum me out a bit.

Instead of:

open Js
open Js.String2
open Belt

would be nice to have:

open Js , Js.String2, Belt
2 Likes

I think these kinds of module opens are not recommended as they can implicitly override other bindings. I don’t think adding a way to use them more easily is a good idea, the language should discourage their use in favour of let {foo, bar} = module(Foo) IMO.

7 Likes

This also is closer to how you do imports in JS which is helpful for newcomers.

yeah but the problem is that in FP you have chain where each module, submodule has to be written over and over again
That’s the beauty of OO, you know the methods from the data container which is way less verbose than FP.
So ‘open’ would help alleviate this but has you said they can override other methods and should be used in the nearest scope and… this means a lot of them.
That’s why I think a more succinct syntax would help.
Another thing is that opens are not that important to be easily readable has other parts of the code.
Having it in one line would help get them out of the way

You can open in a single expression:

let f = x => {
  open Belt.Array

  x
  ->map(...)
  ->keep(...)
}

This is encouraged to avoid polluting the module-level namespace with identifiers.

Yes but sometimes you need more than one open and precisely because you have to repeat the procedure on the exact scopes instead of putting them on the module it would be nice to have them in one terse line