“失败”不再允许?

发布于 2025-01-01 03:27:40 字数 610 浏览 0 评论 0原文

我在 makefile 中定义了要编译的 .ml 列表,由 main/mail.ml 完成。

我有一些failwith“to do”作为这些文件中某些函数的主体。之前,我记得只有当运行时执行需要该函数时才会引发错误。

今天,我所有的 .ml 的编译工作正常:.cmicmx.o 都生成了。但是当我启动主二进制文件时,它似乎并没有首先运行 main.mllet () 中的内容,相反,它似乎首先检查所有makefile 中列表 .ml 的文件,并引发 致命错误:异常 Failure("to do") make: *** [all] Error 2< /code> 当它遇到第一个 faiwith "to做”。

我发现这种行为很奇怪,有人能告诉我可能是什么原因吗?我的 makefilemain.ml 有问题吗?

I have a list of .ml to compile defined in my makefile, finished by main/mail.ml.

I have some failwith "to do" as body of some functions in these files. Before, I remember that it raises an error only when the runtime execution requires that function.

Today the compilation of all my .ml works fine: .cmi, cmx and .o are all generated. But when I launch the main binary, it does not seem to run first what is in let () of main.ml, instead, it seems that it checks first all the files of the list .ml in makefile, and raises Fatal error: exception Failure("to do") make: *** [all] Error 2 when it meets the first faiwith "to do".

I find this behavior very odd, could anyone tell me what might be the reason? There is something wrong in my makefile or main.ml?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱纠缠 2025-01-08 03:27:40

仍然允许 failwith !但这种情况有时也会发生在我身上。

通常问题是,您不是使功能值失败,而是使非功能值失败,这意味着failwith是实际上是在模块初始化期间执行的。因此,您可能在代码中的某个位置编写了:

let f = failwith "TODO"

其中 failwith 在模块初始化时执行而不是

let f x = failwith "TODO"

其中 failwith 在函数初始化时执行f 实际上是用参数调用的。

failwith is still allowed ! But this sometimes happens to me aswell.

Usually the problem is that instead of making a functional value fail, you are making a non-functional value fail, which means that the failwith is in fact executed during module initialization. So it is likely that somewhere in your code you wrote :

let f = failwith "TODO"

where failwith gets executed at module initialisation instead of :

let f x = failwith "TODO"

where failwith gets executed when the function f is actually called with an argument.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文