我目前正在研究真实世界的 Ocaml,但我在运行sum.ml的 OCaml“corebuild”编译版本时遇到了困难:
$ ./sum.native
1
2
3
Uncaught exception:
(Invalid_argument "Float.of_string ")
Raised at file "pervasives.ml", line 31, characters 25-45
Called from file "sum.ml", line 7, characters 44-61
Called from file "sum.ml", line 10, characters 24-46
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢你!
当我尝试重新创建您报告的错误时,我没有看到它。一切正常,我得到的答案是 6.0。可能我使用的是不同版本的 Core。
更新
如果您在最后一个数字后键入额外的换行符,则会出现问题。Float.of_string当输入字符串为空时失败。我认为这就是您所看到的,因为最后一个数字和错误报告之间有一个空行。如果您键入^D以终止输入,则不会有空行。