OCaml:应用于太多参数
为什么代码
if some_bool_var then
begin
output_string some_file "some string"; (* <--- error here *)
end
会生成“应用于太多参数”错误。但如果我把它改成
if some_bool_var then output_string some_file "some string";
它编译得很好。
为什么会这样呢? 谢谢。
Why the code
if some_bool_var then
begin
output_string some_file "some string"; (* <--- error here *)
end
generates "applied to too many arguments" error. But if I change it to
if some_bool_var then output_string some_file "some string";
it compiles fine.
Why is it so?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我非常怀疑你所提供的内容无法编译。我将其复制到顶层,果然我根本没有收到错误。
问题很可能不是您输入的内容,而是您输入的内容之后的内容。我猜你有更多的代码行用于这个特定的函数,因此
end
后面应该有一个分号,表示该命令的结束。将begin ... end
视为( ... )
的替代方案,将...;
视为的替代方案让() = ...在
中。因此,使用begin ... end
并不能替代分号的使用。此外,在
begin
和end
之间结束output_string
调用的分号是不必要的,因为该块不会继续执行更多命令。I'm pretty skeptical that what you've presented doesn't compile. I copied it into the top level and sure enough I'm not getting an error at all.
The problem is most likely not what you've typed but what is after what you've typed. I'm guessing you've got more lines of code for this particular function, thus
end
should have a semi-colon after it denoting the end of that command. Think ofbegin ... end
as an alternative to( ... )
, and...;
as an alternative tolet () = ... in
. Thus, usingbegin ... end
is not a replacement for the use of a semicolon.Also, the semi-colon that ends your
output_string
call betweenbegin
andend
is unnecessary since that block does not continue with more commands.