which I am ignoring because I prefer that the first two approaches allows to namespace usages (Math.pi / math.pi).
Which of these would you prefer if the bindings were not limited to just one property/function of the object being bound?
I thought of mapping the usage of @scope to global singleton objects (as recommended in official docs too) like Math, window, window.location, etc. But this could become tedious and even errorprone (e.g., @scope(("window", "location"))) for a lot of bindings.
I think minting a new module for your bindings is more convenient. I’m guessing the math module may be just an example to illustrate your point, but sticking with it, I could definitely imagine wanting to use those bound math function from functions in other modules/files.
Imagine your bindings live in the Math.res file. In that case, I would rather write Math.floor(8.8) rather than Math.math.floor(8.8).
E.g.
Math.res
@val @scope("Math") external pi: float = "PI"
@val @scope("Math") external floor: float => int = "floor"
type math = {
@as("PI") pi: float,
floor: (. float) => int,
}
@val external math: math = "Math"
Example.res
let x = Math.floor(8.8)
let y = Math.math.floor(8.8)