1

So let's be brief. I learn OCaml for a course I'm currently following, and I'm trying to get intellisense working for the setup I have with VS code on Linux. For that, I have to build my files first. Problem is, when I try to build my file "spellc.ml", I get an error that there is an unbound value.

I have a directory structure like this:

_build/
  src/
    ...
src/
  spellc.ml
  utiles.ml
  ...
.merlin

src/spellc.ml:

module Spellc = struct
    open Utiles
    [...]

    let someFunc x =
        [...]
        let foo = List.map case lst in

    [...]
end

src/utiles.ml:

module Utiles = struct
    [...]

    let case x =
        [...]

    [...]
end

.merlin:

S src
B _build/src

From what I can understand, using an open statement like "open Utiles" should include all expressions and functions contained in the module "Utiles" in my current context so they can be used directly, so that if I use case it'd be like I'm doing Utiles.case. But that doesn't seem to work when I compile using ocamlbuild in the terminal:

ocamlbuild -tag bin_annot src/spellc.byte

I get this error:

Error: Unbound value case

This does not happen when I use the function prefixed by its module (Utiles.case). Could anyone tell me if there's an easy way to make the compilation work with the open statement?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    Put `let case x = ...` at the top level of `utiles.ml`, not inside `module Utiles = struct ... end`. The `utiles.ml` file itself defines a module named `Utiles`: https://ocaml.org/learn/tutorials/modules.html – dkim Mar 25 '17 at 07:03
  • Thanks a lot for the answer! I actually just found this out before reading your comment. Our files were put up like this by our teacher mainly so we can be able to copy paste them into the ocaml interpretor and use their modules. I didn't know that the compiler recognized .ml files as modules themselves. – Alexandre Parent Mar 25 '17 at 18:43

1 Answers1

0

Thanks to dkim I finally found the answer to my problem. What I did not understand is that when you compile OCaml files, a file named utiles.ml already defines module named Utiles, so no need to add the extra declaration module Utiles inside of the .ml file.