OCaml — first impressions
Anders Hovmöller
22

Hi Anders, welcome to OCaml!

I’m practicing this language since 1999 and it’s excellent to read some fresh views from newcomers!

Something very important to know about OCaml is that it made the choice to come with a scarce but solid standard library. This is the same choice than C, C++ or JavaScript but it really different from the decision made by Java or Python — which you seem to know well. Of course this has upsides and downsides. On the list of downsides, the lack of Unicode in the standard library or an apparent competition on standard library extenders (like Batteries or Core — don’t worry much about this, I don’t use any of them and it’s also fine!) Notorious upside is a thin and fast virtual machine and a very stable standard library.

For the specific issue of Unicode it also depends on what you call “support” because Unicode is a very complex standard that as a lot of features. I personally use Camomile but there is hand of other libraries support part or all(?) of the Unicode features. Cf. opam search unicode

It is true that the community did not settle on a build system, it’s probably bound to OCaml being a compiled language that can be used in a wide range of applications. Being a compiled language that can be translated to JavaScript or used to produce a micro kernel means that some users have very specific needs in terms of build scenarios, regarding how to translate static resources in OCaml modules. For this reason, some, as I do, just use makefiles — because of their flexibility and adaptability–while others use more specific build systems which are optimised for some special build scenarios.

I did not know the document you found about ;; and ; and I am sad to say, it is needlessly confusing. First, they are two distinct tokens, so the compiler or the REPL read them differently, just as ++ and + in many other languages using a syntax similar to C. This should clarify the questions about whitespace significance. Just like removing a space in + + will change a sequence of two + into a single ++, removing a space in ; ; will change it into a single ;;. Second the ; is the sequence operator that we use in programs to say “compute this, then that” while the ;; is essentially an end of sequence signal for the REPL to tell the interpreter “please evaluate my statement.” For convenience, the compiler can also digest the ;; but it is not useful in compiled programs. I hope this helps to clarify the situation!

It is a detail but the lack of syntax highlighting could be caused by your terminal running the REPL. In my terminal (plain OS-X terminal) the user-input part triggering the error is underlined. On less capable terminals the system adds an extra line with carets as poor man’s underlining.

Just join us on https://discuss.ocaml.org, we can help you with your first steps as an OCaml-ler! :) Just as for any language, take some time to read other people’s code and look at how they organise their projects. GitHub features many repositories, e.g. https://github.com/michipili

We discussed your post on https://discuss.ocaml.org/t/ocaml-first-impressions/517/6

Show your support

Clapping shows how much you appreciated Michael Le Barbier Grünewald’s story.