Folders as Modules (or yet another thread about long filenames)

Hey

To my understanding, historically the topic of too long filenames caused by the global namespace in OCaml or ReasonML has been considered as something we just have to live with.

However now that ReScript is a separate language that is not promising a full long term backwards compatibility with OCaml, I wonder if there is even a remote possibility to consider solving the problem of too long file names. (it is a problem because every new developer is shocked by it and it does cause minor annoyance all the time with stuff like editor tabs and even git gui tools even for people who are used to living with it)

I’ve been thinking that even an opinionated approach where you could configure ReScript/bs-platform to consider all upper case folder names as empty modules would be a step forward.

I wonder if there could be an appropriate layer in the compiler that would allow interpreting a path
/MyFolder/MyFile.res as a module MyFolder_MyFile before it reaches the OCaml type system which understandably is probably something that is better left untouched.

Anyway, just thought I’d bring this up as this seems to be something that contributes to barrier of entry for new users at least.

1 Like

As long as it is configurable, I don’t mind having a proper “namespace” solution.

I think the magic of 1 file == 1 module applies equally well to 1 directory == 1 namespace.

I also think you can kinda achieve that now with a monorepo, but you would essentially need a bsconfig.json for every folder.

2 Likes

After writing my post, I started pondering if one can get rid of the vendor namespace (first part of the filename) with monorepo structure nowadays. That would already help a bit.

But maybe it increases the collision risk with 3rd party libs?

Take a look at this issue.
I asked @Hongbo what he thinks about that.
Personally I don’t like to directories act as module/namespace unless with a configuration smiliar to what i’ve described in the issue.

1 Like