This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line.
The only real reason that I can see to choose OCaml over Haskell is that if you learn OCaml, you might be able to work at Jane Street. Is there a strong argument for abandoning my Haskell-ing for OCaml?
This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line.
That's easily fixed: only the toplevel requires ;; (to commence evaluation of the phrases you've typed in). Just don't use it in normal code and everything will parse fine.
Would you care to share an example? I've never encountered a justifiable need to write ;; outside the REPL. The only uses of ;; I've encountered "in the wild" were hardly reasonable: essentially top-level code that was not wrapped in a "let () = ..." statement.
I don't recall seeing that recommendation before this thread. That may just be my blindness in skimming things too quickly. In any case, I think it indicates a wart in the language when you have to wrap everything in otherwise useless let blocks just to get it to parse.
For reference, here is the tutorial's example reformatted in a more reasonable way:
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 ()
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.
The Graphics module is a core Ocaml library that is always available. In order to use it, it must be linked on the command line, similar to many other languages. Installing an unrelated OpenGL binding didn't magically make "ocaml o.ml" work. Based on this and the obvious trolling of your final paragraph, I'm hesitant to believe anything you said is true.
Seriously. You are so biased that it is easier for you to believe that other people are downright lying than to accept inconvenient truth. I was running it in the interpreted mode. Isn't that how one is supposed to run tutorials code? And obviously I've added the following:
#load "graphics.cma";;
into the file first. And forgot about it, when writing the post. So no magic here. "Beautiful" syntax by the way.
And no, I wasn't trolling. I just wanted to see what that recursion would do. The code is not exactly crystal clear there, with names like start_x and such. But it really did not work. And the syntax is really ugly. And you can believe what you like.
Dont judge syntax when you are new to a language. Few syntaxes have the tendency to never grow on you, but it is surprising how most do, even when your first impressions were pretty bad. Remarkable abilities of the human brain !
Tried it here and it worked, both on Arch Linux with OCaml 4.01.0 and a clean Ubuntu/12.04 with OCaml 3.12.1:
$ ocaml graphics.cma test.ml
Debian splits OCaml into two packages: ocaml-nox (no X) and ocaml (everything). Make sure you're not using the nox version, and make sure you have an X server available (i.e. you're not running it on a headless server or something).
Still, "fatal I/O error" is a terrible error message.
Comments
This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line.
The only real reason that I can see to choose OCaml over Haskell is that if you learn OCaml, you might be able to work at Jane Street. Is there a strong argument for abandoning my Haskell-ing for OCaml?
That's easily fixed: only the toplevel requires ;; (to commence evaluation of the phrases you've typed in). Just don't use it in normal code and everything will parse fine.
That's an exaggeration. There are circumstances in files where it's necessary. I didn't realize this, which hung me up for a long time.
Would you care to share an example? I've never encountered a justifiable need to write ;; outside the REPL. The only uses of ;; I've encountered "in the wild" were hardly reasonable: essentially top-level code that was not wrapped in a "let () = ..." statement.
I don't recall seeing that recommendation before this thread. That may just be my blindness in skimming things too quickly. In any case, I think it indicates a wart in the language when you have to wrap everything in otherwise useless let blocks just to get it to parse.
Don't put non-let expressions at the top level?
;; is a special token used only in the REPL to force evaluation, it is not something you ever use in real code.
Well, that explains a lot! I'm embarrassed I never got past that.
Don't feel too bad about it. The official OCaml tutorial is also confused:
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.
For reference, here is the tutorial's example reformatted in a more reasonable way:
The trouble with Ocaml is that you will probably get something like:
And after you've googled for a while and had done: The thing would install 23(!) packages. And after that you will get: 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.The Graphics module is a core Ocaml library that is always available. In order to use it, it must be linked on the command line, similar to many other languages. Installing an unrelated OpenGL binding didn't magically make "ocaml o.ml" work. Based on this and the obvious trolling of your final paragraph, I'm hesitant to believe anything you said is true.
Seriously. You are so biased that it is easier for you to believe that other people are downright lying than to accept inconvenient truth. I was running it in the interpreted mode. Isn't that how one is supposed to run tutorials code? And obviously I've added the following:
into the file first. And forgot about it, when writing the post. So no magic here. "Beautiful" syntax by the way.And no, I wasn't trolling. I just wanted to see what that recursion would do. The code is not exactly crystal clear there, with names like start_x and such. But it really did not work. And the syntax is really ugly. And you can believe what you like.
Dont judge syntax when you are new to a language. Few syntaxes have the tendency to never grow on you, but it is surprising how most do, even when your first impressions were pretty bad. Remarkable abilities of the human brain !
Does that mean that K syntax could grow on me? http://en.wikipedia.org/wiki/K_(programming_language)
For this old C programmer, Python proved to have the most friendly syntax.
Tried it here and it worked, both on Arch Linux with OCaml 4.01.0 and a clean Ubuntu/12.04 with OCaml 3.12.1:
$ ocaml graphics.cma test.ml
Debian splits OCaml into two packages: ocaml-nox (no X) and ocaml (everything). Make sure you're not using the nox version, and make sure you have an X server available (i.e. you're not running it on a headless server or something).
Still, "fatal I/O error" is a terrible error message.
Ocaml 3.12.1; Ubuntu 13.10. X server is available, Desktop is MATE 1.6.0, OpenGL also seems to work (glxgears works).
Pull requests welcome:
https://github.com/ocaml/ocaml.org/tree/master/site/learn/tu...