Proposal: improve external bindings

External bindings today, for me, are unintuitive. Here’s a proposal to improve the intuition of the bindings.

Currently it’s something like this:
[the module] external [the declaration + signature] = [the variable]

Can it be improved to this?
[the module + variable] external [the declaration + signature]

Hypothetical examples:
For Browser APIs this could be something like

@browser("document", "getElementById")
external getElementById: (document, string) => Dom.element

For node modules this could be something like

type express

@node("express")
external express:  unit => express 

@node("express", "get") 
external get: (express, string, handler) => unit

For the JS files in the user’s project this could be something like

@local("./student", "default")
external studentName: string

The decorators tell us where the bindings are coming from. @browser would be for Browser APIs, @node would be for node APIs and @local(or maybe @source) would be for JS sources in the project. This would be easier for JS developers to understand, when they’re being introduced to ReScript-JS interop.

Please provide feedback if this sounds interesting.

2 Likes