[英]how to invoke module in ocaml
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. 我写了一个ocaml文件,其中包含Vector模块和Matrix模块,并且我想在Matrix模块中调用Vector模块,但是编译器说Vector模块是未绑定的模块。 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) 它们在同一个.ml文件中,如何在Matrix模块中编写代码以调用Vector模块(不使用functor)
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
): 这是一个
m.ml
的小示例( 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. 要知道的一件事是,每个OCaml文件都引入了一个以该文件命名的模块。 So the modules in the above example are named
M.Vector
and M.Matrix
, because the file is named m.ml
. 因此,上面示例中的模块名为
M.Vector
和M.Matrix
,因为文件名为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.
理想情况下,您应该显示最少的代码来重现该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.