-1

I have wrote a ocaml file which includes Vector module and Matrix module, and I want to invoke Vector module in the Matrix module, but the compiler said that Vector module is unbound module. I don't know why,here is my code

module Vector = 
Struct
   body
end

module Matrix = 
Struct
    body
end

they are in the same .ml file, how can I write code in Matrix module to invoke Vector module(exclude using functor)

高亮节
  • 169
  • 1
  • 1
  • 9
  • 2
    `Struct` should have a lowercase "s": `struct` is the right keyword. Could you show us your actual code or at least a minimal example reproducing your problem? – PatJ Mar 20 '15 at 05:21

1 Answers1

3

There's nothing wrong with the code you show, so it's not really possible to answer. Here is a tiny example that works (m.ml):

module Vector =
struct
    let f x = x + 7
end

module Matrix =
struct
    let g x = 2 * Vector.f x
end

The compiler has no trouble with it:

$ ocamlc -c m.ml
$ 

One thing to be aware of is that every OCaml file introduces a module named after the file. So the modules in the above example are named M.Vector and M.Matrix, because the file is named m.ml.

If this doesn't help, you'll need to show more code. Ideally, you should show the smallest amount of code that reproduces the problem.

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108