As you now know, all .re files are modules and all modules are globally available—including nested ones. By default, all types and bindings can be accessed from anywhere by providing the namespace. However, doing this over and over quickly becomes tedious. Luckily, we have a few ways to make this more pleasant:
/* Foo.re */
type fromFoo =
| Add(int, int)
| Multiply(int, int);
let a = 1;
let b = 2;
Next, we'll use the Foo module's fromFoo type along with it's bindings within another module in different ways:
- Option 1: Without any sugar:
/* Bar.re */
let fromFoo = Foo.Add(Foo.a, Foo.b);
- Option 2: Alias the module to a shorter name. For example, we can declare a new module F and bind it to the existing module Foo:
/* Bar.re */
module F = Foo;
let fromFoo = F.Add(F.a, F.b);
- Option 3: Locally open the module using the Module.() syntax. This syntax...