http://ocaml.org/learn/tutorials/structure_of_ocaml_programs...
(someone really should go through these tutorials and fix the various misleading parts)
Basically, the rule is to use "let () = ..." for your main block / top-level code and don't use ";;" ever.
open Random
open Graphics
let rec iterate r x_init i =
if i = 1 then x_init
else
let x = iterate r x_init (i - 1) in
r *. x *. (1.0 -. x)
let main () =
self_init ();
open_graph " 640x480";
for x = 0 to 639 do
let r = 4.0 *. (float_of_int x) /. 640.0 in
for i = 0 to 39 do
let x_init = Random.float 1.0 in
let x_final = iterate r x_init 500 in
let y = int_of_float (x_final *. 480.) in
Graphics.plot x y
done
done;
ignore (read_line ())
let () = main () $ ocaml o.ml
File "o.ml", line 2, characters 0-13:
Error: Unbound module Graphics
And after you've googled for a while and had done: sudo apt-get install liblablgl-ocaml-dev
The thing would install 23(!) packages. And after that you will get: $ ocaml o.ml
Exception: Graphics.Graphic_failure "fatal I/O error".
After which, if you've been in the industry for a decade or two, you will probably decide that you'd better stop wasting your time on that particular language. Besides. It just looks ugly. Almost as ugly as perl.https://github.com/ocaml/ocaml.org/tree/master/site/learn/tu...