简体   繁体   English

(Ocaml)可视代码上的未绑定模块错误

[英](Ocaml) unbound module error on visual code

I have just started to learn Ocaml.我刚开始学习Ocaml。 I'm using visual code as my IDE on Ubuntu, and I have OCaml extension and merlin installed.我在 Ubuntu 上使用可视代码作为我的 IDE,并且安装了 OCaml 扩展和 merlin。

and I have the following problem -我有以下问题 -

my workspace folder contains only 2 files: a.ml and b.ml.我的工作区文件夹仅包含 2 个文件:a.ml 和 b.ml。

In the file a.ml I have defined a module named "COOL", and in the file b.ml I wrote:在 a.ml 文件中,我定义了一个名为“COOL”的模块,在 b.ml 文件中我写道:

~ b.ml ~

open COOL;;

I get an error that says "Unbound module COOL merlin"我收到一条错误消息,提示“未绑定模块 COOL merlin”

Is there any way to make it see the module on file a.ml?有没有办法让它看到文件 a.ml 上的模块? I tried searching for solution, I saw something with makefile and.merlin and B build but I didn't understand it, I don't have anything but the 2 files I mentioned.我尝试寻找解决方案,我看到 makefile 和.merlin 和 B 构建但我不明白,除了我提到的 2 个文件之外我什么都没有。 I would be happy if someone can tell me what exactly should be done in order for this little example to work.如果有人能告诉我应该做什么才能让这个小例子起作用,我会很高兴。

tl; tl; dr: do ocamlc -c a.ml (or whatever your compilation command is) in order to generate the a.cmi file that merlin will use to get the list of symbols defined in module A .博士:执行ocamlc -c a.ml (或任何您的编译命令)以生成 merlin 将用于获取模块A中定义的符号列表的a.cmi文件。

Apart the fact that in b.ml your module is indeed named A.COOL (unless you open A before open COOL ) as mentioned by glennsl, the point is that merlin is, as far as I know, only watching the current file being edited, ie b.ml in your case.除了在b.ml中你的模块确实被命名为A.COOL (除非你在open COOL之前打开open A ),正如 glennsl 提到的那样,关键是,据我所知, merlin只观看正在编辑的当前文件,即b.ml在您的情况下。 In order to have access to external symbols, you thus need to have compiled the other files (or at least their corresponding .mli if they exist), in order to have the relevant .cmi files available to merlin.为了访问外部符号,您需要编译其他文件(或者至少编译它们对应的.mli ,如果它们存在的话),以便 merlin 可以使用相关的.cmi文件。

This is implicit in the paragraph of the documentation describing build paths, which says "[merlin] needs to know where to find the cmi files of the other modules of your project", ie those files need to exist in the first place.这在描述构建路径的文档段落中是隐含的,它说“[merlin] 需要知道在哪里可以找到项目其他模块的 cmi 文件”,即这些文件首先需要存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM