I’ve been using OCaml for a while and I definitely feel that it is a “fast, secure, and productive” language. If Rust was your closest language, I think you’ll find something that you’ll like in OCaml.
I’ll try my best to answer some of your questions, but some of the more experienced people here might have a better perspective.
If OCaml is so fantastic, why it’s not more used?
I think the popularity of a programming language is largely circumstantial. Some languages are popular now because they were the best choice 20 years ago and now there are millions of lines of code that have to be maintained. Some languages are popular because they found a niche and built a community around it.
My personal opinion is that OCaml is “better” as a language than others, but being a better language doesn’t necessarily guarantee users. Even for something like a programming language, there’s a lot of marketing (word-of-mouth or otherwise) that has to happen to maximize popularity.
I would also say that there’s a catch-22 around OCaml’s popularity: some new users don’t want to use it because its library ecosystem is (relatively) small, but there can’t be a larger library ecosystem unless there are more users to write the libraries. That being said, you might find that OCaml is already sufficient for your needs.
Most of what I’m doing is web development. Is OCaml suitable for the task?
I’m no web developer, but I’ve found OCaml to be suitable for targeting JS with Js_of_ocaml. There are libraries like opium and eliom that should be helpful.
Does OCaml has the same problem as Scala?
I don’t think so. OCaml does have OOP features, but they are used infrequently. A functional style is greatly preferred by most libraries and developers. All functions are curried by default and the “pipeline”
|> operator makes it easy to write readable function chaining. OCaml does have exceptions, but like objects, they tend to be used infrequently and functions that can raise exceptions are typically marked clearly.
OCaml doesn’t have typeclasses like Haskell/Rust or implicits like Scala, but it has an incredibly powerful module system that is as expressible. Modules in OCaml are my favorite part of the language and they seem to be unrivaled by other languages.
What’s the difference between OCaml and Reason, ReScript, Buckescript, and so on?
OCaml is the language and compiler (to native or bytecode).
Js_of_ocaml is an OCaml-to-JS compiler that works in the OCaml ecosystem of libraries. You can use the latest version of the OCaml language with most OCaml libraries. It should be easy to share code between native and JS projects.
Reason is an alternative syntax for OCaml that looks more like JS. It has the same type system as OCaml and can be used in the same ways (native, JS). With the release of ReScript, I am personally not very confident in its future.
Bucklescript is (was) an OCaml-to-JS compiler that integrates closer with the NPM/JS ecosystem. It is an older fork of the OCaml compiler and I don’t think it can use OCaml libraries very easily.
ReScript is two things:
- A new alternative syntax that looks similar to Reason with more changes. It supports less OCaml language features and can only be used when compiling to JS.
- A rebranding of the Bucklescript compiler. It can compile from ReScript syntax. OCaml and Reason syntax are also supported (for now) but they are referred to as “old(er) syntax” and it is clear the focus is on Rescript syntax. Like Bucklescript, it is still on an older OCaml compiler version.
I realize these different technologies can get confusing. My choice is to stick to the original OCaml language and use Js_of_ocaml if I need to target JS. I’ve been very happy so far.