tl;dr – Is there a way to use the -nolabels
compiler option?
With the OCaml compiler, there is the option -nolabels
which is used to ignore non-optional labels in types. One thing you may use it for is to provide a labels version of a module, eg Foo
and FooLabels
, in which you don’t have to rewrite the whole module implementation, rather just include the non labels version and write a new interface. (Here is an example in this ocaml library: set the nolabels option, include the module, write labels interface).
That option seems to be missing from the bsc
executable (and it doesn’t work if you add the option to your bsconfig.json file either, like with "bsc-flags": ["-nolabels"]
), so I’m wondering if there is any way to get that behavior now with Rescript. Second question would be the rational as to why it unavailable (note: I’m not saying it should or shouldn’t be available, just wondering the why of it).
Interestingly, there is this bit of commented out code in the ninja file:
// if (mod.endsWith("Labels")) {
// overrides.push({ key: "bsc_flags", value: "$bsc_flags -nolabels" });
// }
I checked the git blame for this and it looks like a pre-v10 commit, so then I went to the changelog for v10 and saw this:
- hide most bsc options, officially supported bsc flags (this is not a breaking change, those internal options are still there but subject to removal in the future)
So it seems that this “trick” was being used at some point in the past, but isn’t really supported any longer. (Though it does say the options are still there, I’m not sure how to use them other than hacking on the code.)
I guess a follow up to this would be, is there any consensus on APIs with labels vs no labels among rescripters? In OCaml, some like labels, some don’t, which is why you may see the labels trick above…you write your one implementation, then provide both labeled and non-labeled interface.
For reference, it seems that rescript core uses labels on the non-“main” type in some modules, but not in other modules.
(Actually, the labels/no-labels question could probably make a good topic on its own.)