Alexandre Parent
Alexandre Parent

Reputation: 11

ocamlbuild error unbound value

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?

Upvotes: 1

Views: 1411

Answers (1)

Alexandre Parent
Alexandre Parent

Reputation: 11

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.

Upvotes: 0

Related Questions