I started programming with Ocaml 2 days ago, I have been through the basic stuff and I wanted to start trying to create Processes.
In the book I am using the tell me to use the Unix module, so far so good... But I get this error when I try to run a simple code that prints the time:
open Unix ;;
let t = Unix.localtime (Unix.time ());;
Printf.printf "Today is day %d of the current year.\n" t.tm_yday ;;
And I get this error:
Error: Unbound module Unix
I searched for an answer to this and I found I should compile my code with "unix.cma" linked, after this I was able to compile, but the code does nothing.
I know it might be a very noobish question, but I can't keep going on without this. Is a library missing?
If I run in top level it says the #load is and unbound value also
!
Thank you for your time!
Edit:
I recompile it with the "unix.cma" linked, and obtained the same error:
Error: Unbound module Unix
Might be a library issue?
I did ocamlc -where and it all seems fine, meaning all the usual libraries are in the PATH, including unix.cma
Solved
It was all due to a bad installation of Ocaml. Thank you Jeffrey Scofield
It works here for me. Here is a toplevel session (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 = ()
#
Here is a session with the compiler:
$ 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.
If these don't work for you, my only theory is that your OCaml installation isn't complete. What type of system are you using?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With