Failed to destroy functor (module)

This syntax will be very useful - is there a reason why this does not work? Thank!

module Foo = {
  let bar: string = "bar"
};

let bar = Foo.bar; /* works */
let { bar } = Foo; /* Unbound record field bar */

Try it now!

+4
source share
2 answers

Closest you can do the following:

module Foo = {
  let bar = "bar";
  let baz = "baz";
};

let (bar, baz) = Foo.(bar, baz);
+7
source

Unable to destroy module in OCaml / Reason.

Equivalent OCaml Code Generates 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 fine by entering all the values ​​specified in Foo into the local area, you can use open Foo. https://reasonml.imtqy.com/try.html?reason=LYewJgrgNgpgBAMRCOBeOBvOsAucBGAhgE4BccAzjsQJYB2A5mnAERHEtwC+A3AFAgADjDqJk-AFIUAdFBAMAFOwCUQA

module Foo = { let bar: string = "bar" };
open Foo;
Js.log(bar)

Foo , include Foo. https://reasonml.imtqy.com/try.html?reason=LYewJgrgNgpgBAMRCOBeOBvOsAucBGAhgE4BccAzjsQJYB2A5mnAERHEtwC+A3AFD0AxlAhh4SEPwBSFAHRQQDABTsAlEA

module Foo = { let bar: string = "bar" };
include Foo;
Js.log(bar)
+3

Source: https://habr.com/ru/post/1694794/


All Articles