我两天前就开始用Ocaml编程了,我已经了解了一些基本的东西,我想开始尝试创建过程。
在书中我用的是告诉我使用Unix模块,到目前为止.但是,当我试图运行一个打印时间的简单代码时,我会得到这个错误:
open Unix ;;
let t = Unix.localtime (Unix.time ());;
Printf.printf "Today is day %d of the current year.\n" t.tm_yday ;;我得到了一个错误:
Error: Unbound module Unix
我搜索了这个问题的答案,我发现我应该用"unix.cma“链接来编译我的代码,之后我就可以编译了,但是代码什么也没做。
我知道这可能是个很无聊的问题,但没有这个我就不能继续下去了。图书馆不见了吗?
如果我在最高层运行,上面写着#load is and unbound value also!
谢谢您抽时间见我!
编辑:
我用"unix.cma“链接重新编译它,并获得了相同的错误:Error: Unbound module Unix
可能是图书馆的问题?
我做了ocamlc -where,这一切看起来都很好,这意味着所有常用的库都在其中,包括unix.cma。
解决了
这都是因为Ocaml安装得不好。谢谢杰弗里·斯科菲尔德
发布于 2012-12-04 00:28:32
在这里对我有用。下面是一个toplevel会话(MacOSX10.8.2):
$ ocaml
OCaml version 4.00.0
# #load "unix.cma";;
# open Unix;;
# let t = Unix.localtime (Unix.time ());;
val t : Unix.tm =
{tm_sec = 39; tm_min = 27; tm_hour = 16; tm_mday = 3; tm_mon = 11;
tm_year = 112; tm_wday = 1; tm_yday = 337; tm_isdst = false}
# Printf.printf "Today is day %d of the current year.\n" t.tm_yday;;
Today is day 337 of the current year.
- : unit = ()
# 下面是编译器的会话:
$ cat doy.ml
open Unix
let t = Unix.localtime (Unix.time ());;
Printf.printf "Today is day %d of the current year.\n" t.tm_yday
$ ocamlc -o doy unix.cma doy.ml
$ doy
Today is day 337 of the current year.如果这些不适用于您,我唯一的理论是您的OCaml安装没有完成。您使用的是什么类型的系统?
https://stackoverflow.com/questions/13694140
复制相似问题