0

Say I have two files:

foo.re
bar.re

Say I now have, at the top of bar.re

open MyProject.Foo;

This fails to compile with:

This module is not a structure; it has type
  (module MyProject.Foo)

If I rerun compilation, everything works fine

If I change that line to just open Foo; everything compiles fine.

Why am I observing this behaviour?

glennsl
  • 28,186
  • 12
  • 57
  • 75
Abraham P
  • 15,029
  • 13
  • 58
  • 126

1 Answers1

0

ReasonML treats each file as a module, the practice is to uppercase the file name so

Foo.re
Bar.re

let's also suppose that we define a function in Foo call bar and another in Bar call foo.

so we would have:

/* Inside Foo.re */
let bar = string => {}

/* Inside Bar.re */
let foo = string => {} 

from with another module, which we have called Main.re, we can reference the above as.

let myResult = Foo.bar("happy");
let ourResult = Bar.foo("days);

or

open Foo, Bar;

let myResult = bar("happy");
let ourResult = foo("days");

So when asked for open MyProject.Foo, you were asking for the submodule Foo within the module MyProject, which does not exist. Of course, if you created MyProject.re and added a module to that file called Foo, then your open MyProject.Foo would work fine.

Further references:

The underlying Ocaml which the reasonML modules are based on. The Basic modules section from Axel Rauschmayer book on ReasonML

Ray King
  • 66
  • 1
  • 7