This syntax would be very useful—is there a reason for this not working? Thanks!
module Foo = {
let bar: string = "bar"
};
let bar = Foo.bar; /* works */
let { bar } = Foo; /* Unbound record field bar */
This syntax would be very useful—is there a reason for this not working? Thanks!
module Foo = {
let bar: string = "bar"
};
let bar = Foo.bar; /* works */
let { bar } = Foo; /* Unbound record field bar */
The closest you can do is something like this:
module Foo = {
let bar = "bar";
let baz = "baz";
};
let (bar, baz) = Foo.(bar, baz);
It is not possible to destructure a module in OCaml/Reason.
The equivalent OCaml code produces a syntax error on line 3
module Foo = struct let bar: string = "bar" end
let bar = Foo.bar
let struct bar end = Foo
File "", line 3, characters 4-10: Error: Syntax error
If you are OK with bringing all of the values specified in Foo into the local scope, then you can use open Foo
.
https://reasonml.github.io/try.html?reason=LYewJgrgNgpgBAMRCOBeOBvOsAucBGAhgE4BccAzjsQJYB2A5mnAERHEtwC+A3AFAgADjDqJk-AFIUAdFBAMAFOwCUQA
module Foo = { let bar: string = "bar" };
open Foo;
Js.log(bar)
If you also want to export all of the definitions in Foo through the current modules exports, you can include Foo
.
https://reasonml.github.io/try.html?reason=LYewJgrgNgpgBAMRCOBeOBvOsAucBGAhgE4BccAzjsQJYB2A5mnAERHEtwC+A3AFD0AxlAhh4SEPwBSFAHRQQDABTsAlEA
module Foo = { let bar: string = "bar" };
include Foo;
Js.log(bar)