[英]Error: Unbound module Unix in Ocaml
我在2天前開始使用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,一切看起來都很好,這意味着所有常用的庫都在PATH中,包括unix.cma
解決了
這完全是由於Ocaml安裝不當造成的。 謝謝傑弗里斯科菲爾德
它適用於我。 這是一個頂級會話(Mac OS X 10.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安裝不完整。 你使用什么類型的系統?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.