受到这个SO问题答案的启发,我采用代码来检查尾递归的命令循环:
let rec nothingfunc i =
match i with
| 1000000000 -> 1
| _ -> nothingfunc (i+1)
let nothingloop1 () =
let i = ref 0 in
while !i < 1000000000 do incr i done;
1
let timeit f v =
let t1 = Unix.gettimeofday() in
let _ = f v in
let t2 = Unix.gettimeofday() in
t2 -. t1
let () =
Printf.printf "recursive function: %g s\n%!" (timeit nothingfunc 0);
Printf.printf "while loop with ref counter …
Run Code Online (Sandbox Code Playgroud) 我正在使用这些文件测试单独的编译:
testmoda.ml
module Testmoda = struct
let greeter () = print_endline "greetings from module a"
end
Run Code Online (Sandbox Code Playgroud)
testmodb.ml
module Testmodb = struct
let dogreet () = print_endline "Modul B:"; Testmoda.greeter ()
end
Run Code Online (Sandbox Code Playgroud)
testmod.ml
let main () =
print_endline "Calling modules now...";
Testmoda.greeter ();
Testmodb.dogreet ();
print_endline "End."
;;
let _ = main ()
Run Code Online (Sandbox Code Playgroud)
现在我生成.mli文件
ocamlc -c -i testmoda.ml >testmoda.mli
Run Code Online (Sandbox Code Playgroud)
和testmoda.cmi在那里.
接下来,我创建.cmo文件没有错误:
ocamlc -c testmoda.ml
Run Code Online (Sandbox Code Playgroud)
很好,所以使用testmodb.ml也一样:
strobel@s131-amd:~/Ocaml/ml/testmod> ocamlc -c -i testmodb.ml >testmodb.mli
File "testmodb.ml", line 3, characters …
Run Code Online (Sandbox Code Playgroud)