Hey, I’m new here. Trying to learn some OCaml, I would like to share my first impressions, and my frustration. I hope this is okay, and that I’m not in the wrong category. (Also, my english is quite bad.)
- The ecosystem is intimidating to me. There are many different tools, the “standard environment” implies : OCaml compiler, OPAM, Dune, Emacs, Tuareg, Merlin, and so on. I come from Racket (mainly), where things are obviously easier. I’m not saying this is a bad thing, I guess it’s the “UNIX philosophy”, just… intimidating. I would love having an IDE like DrRacket for OCaml. Learning would be much more fun. Emacs is a fine IDE, but I’m here to learn a language, not a complex text editor and sixty-four other tools.
- OCaml is not “batteries included”, which means, I need external libraries to write programs and do concrete stuff. However, to install and use a library properly is not a straightforward thing (for me at least), and external libraries are less documented than stdlib (generally, code and interface files are the documentation itself). Because of this, I tend not to use external libraries at all, which means I don’t have http, concurrency, GUI, or whatever.
- Because of this, OCaml feels like a language for UNIX hackers working on compilers or trading systems or automated proofs, not a language for everyone. OCaml hackers develop tools for themselves when they need to, and I guess they don’t need a fancy IDE or things like that.
On the bright side, the OCaml community seems very welcoming, and aware of these difficulties. I understand that the ecosystem is evolving and the situation was much worse fifteen years ago.
About the language itself :
- It generally looks good and well designed (there is some eccentricity here and there, but the general ideas are sound, which is impressive for an “old” language).
- It also looks big, and a lot of things to learn.
- The module system, while powerful, scares me a little bit… That and the fact that I have to write an interface file for each module (which means a lot of files, and remember that I don’t have any IDE…), I’m often tempted to write my programs in one big file (which is bad, since the main tool in OCaml for encapsulation and structure is the module system).
- “Objective Caml” people sell it like a multi-paradigm language who can do OOP, but in practice, it seems people don’t bother with objects at all (me neither, to be honest). If OCaml could be redesigned without compatibility issues, I wonder if it still had objects ?
- I miss comprehension/iteration facilities (like Racket’s for, for/list, for/fold, or even the baroque loop of Common Lisp). OCaml people seem to encourage a functional style over an imperative one (when it makes sense), but since I don’t have list comprehensions or anything, too often I have to chose between “manual” recursion or smart composition of higher order functions (which is not very readable and feels a bit “low level”).
- List comprehensions are just an example, but generally : the type system and module system are fantastic and obviously a lot of efforts were made into it, but the rest of the language often feels rough and blunt or low-level. Other languages have a lot of practical things to make life easier (I’m thinking about Racket, Haskell, Python, for instance). In OCaml the answer is either “write it yourself” or “use X library with PPX extension”. The comparison with Haskell is canonical, because the OCaml language is more practical in essence, but Haskell folks made the language feel more modern and sometimes more practical (I know Haskell has a bigger community and it helps).
- For a beginner like me, it’s hard to learn the “standard way” to do things in OCaml. For instance, let’s talk about error handling. It seems like some people use exceptions, some people use options in a simple way, some people use options in a monadic way, some people use everything. It’s very confusing, could you explain? (Edit : I just noticed than Stream.next raises an exception, while Stream.peek returns an option type…)
Bonus note : parts of the reference manual feel outdated. I was reading the Genlex module reference and it shows code with Camlp4. It took me a long time to understand why this
[< stream >] syntax doesn’t work anymore.
Sorry for all these complains, I don’t want to sound harsh or anything. I think the language and the community are worth the effort. Feel free to help me or correct me where I’m wrong.