“失败”不再允许?
我在 makefile
中定义了要编译的 .ml
列表,由 main/mail.ml
完成。
我有一些failwith“to do”
作为这些文件中某些函数的主体。之前,我记得只有当运行时执行需要该函数时才会引发错误。
今天,我所有的 .ml
的编译工作正常:.cmi
、cmx
和 .o
都生成了。但是当我启动主二进制文件时,它似乎并没有首先运行 main.ml
的 let ()
中的内容,相反,它似乎首先检查所有makefile
中列表 .ml
的文件,并引发 致命错误:异常 Failure("to do") make: *** [all] Error 2< /code> 当它遇到第一个
faiwith "to做”。
我发现这种行为很奇怪,有人能告诉我可能是什么原因吗?我的 makefile
或 main.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仍然允许
failwith
!但这种情况有时也会发生在我身上。通常问题是,您不是使功能值失败,而是使非功能值失败,这意味着
failwith
是实际上是在模块初始化期间执行的。因此,您可能在代码中的某个位置编写了:其中
failwith
在模块初始化时执行而不是:其中
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 :where
failwith
gets executed at module initialisation instead of :where
failwith
gets executed when the functionf
is actually called with an argument.