It's cool to see a link about learning OCaml so high on HN. I started teaching myself OCaml a few months ago and I really like it. Here's a few things I like so far and why I think anyone that uses Go or Rust should give OCaml a look:<p>1. OCaml compiles to a binary like Go and Rust do<p>2. The type system is helpful without being a huge burden on learning/productivity (unlike Rust and Haskell)<p>3. Garbage collection<p>4. Pattern matching and algebraic data types (like Rust)<p>5. OCaml is plenty fast at CPU bound work(slower than Rust, faster than Go) despite not being parallel (yet)<p>Those are my takeaways of what I enjoy about OCaml so far. It has been the most approachable typed functional language that I've looked at yet! Depending on the type of things you want to learn and problems you want to solve, Your Mileage May Vary.
This is also great cheat sheet for someone still getting used to the OCaml syntax.<p>I usually advise people to pretend that double semicolons don't exist for anything but the interactive top level. In source files, you can forget about double semis entirely as long as you just remember to always assign the result of an imperative statement to the dummy "_" name.<p><pre><code> let _ = print_string "hi"
</code></pre>
Then you can think of ;;<enter> as merely a fancy way of hitting the return key in the interactive REPL. There's also a way to use a different key mapping (control+enter) instead of ;; in utop, so there would be no reason to even acknowledge the existence of double semis.
<a href="https://github.com/diml/utop/issues/131" rel="nofollow">https://github.com/diml/utop/issues/131</a>
im quite amazed that ocaml seems to be on a rise (judging from how often i've recently seen it on here). it reminds me of the time i started to dig into it more than a decade ago when mldonkey [0] was a thing.<p>also, this is the way to briefly introduce a programmer to a new language. just show the commented syntax. i just hate reading all the prefaces and texts of language manuals. it's good they're there but i'm just loosing interest too quickly if you don't show me code.<p>[0] <a href="https://en.wikipedia.org/wiki/MLDonkey" rel="nofollow">https://en.wikipedia.org/wiki/MLDonkey</a>
There are also more links/resources on the OCaml website.<p><a href="http://ocaml.org/learn/books.html" rel="nofollow">http://ocaml.org/learn/books.html</a>
It seems `int_of_float` and `float_of_int` are deprecated by the Jane Streets Core library. It even throws errors on utop. I believe they need to be replaced by `Int.of_float` and `Float.of_int` respectively.<p>EDIT: Some more corrections:<p>1. `List.hd []` doesn't raise an error as its return type is an option. So the result is a `None`.<p>2. `List.map` and `List.filter` arguments should be reversed. First argument should be a list and the second should be the mapping function.
I do really like OCaml, although Rust is the one I'm starting to look to where in the past I'd consider OCaml (yes, two different languages, but similar in practical function approach and safety).<p>The one things that I absolutely can't stand about OCaml is the lack of an easy, available, include-in-the-standard-library, debugging function. Every damn time I work with OCaml, I end up having to write annoyingly time-consuming "print_blah_blah" functions to handle debugging. And such a debugging feature should handle errors already, and not return the Option type. I shouldn't have to write a function to handle errors on a debugging statement.<p>And yes, I'm sure there are some nice versions of this already available in 3rd-party libraries, but this should be in the standard library.