"What are the benefits of OCaml as a programming language" is indeed an opinion-based question, and one that I'm not going to tackle here. However, I work on the Hack team at Facebook, and have worked closely with the Flow team, so I can answer the question I think you intended to ask: "Why did Facebook pick OCaml to build Hack and Flow?"
- The biggest reason is that OCaml has brilliant support for defining your own datatypes, and then pattern matching on them. Most of what Hack and Flow do are operations over various forms of an AST, and having a really nice way to express "if you see this kind of node with that kind of node inside it, do this thing" is invaluable. Take a look at the definition of subtyping in Hack -- it's certainly complicated, but at its heart it's just a big pattern match over a pair of types, and would be unreadably complex in any language without pattern matching.
- OCaml is largely a functional language, with great support for first-class functions and immutable data structures. Similarly to the above, when you're doing typechecking, you end up doing a lot of different kinds of maps and folds over AST nodes, and functional languages express that really concisely. For example, typing a block of code is literally just a
fold_left
over the statements it contains.
- But it's not purely functional. It's "impure" -- sometimes, mutable state, using exceptions, or similar is just the nicest way to express something. But most importantly, it means that you don't need any sort of complicated acrobatics or mental model switch or anything to call into C functions via an FFI. Both Hack and Flow use the same model for multithreading: a specially
mmap
'd region shared between different fork
'd processes, containing a shared, lockless hash table. That's the sort of thing I wouldn't want to express in any language except C -- and that's exactly what we do. The OCaml code can call a couple magic functions without being any the wiser that it's actually C under the hood. (As an aside, I'm going to do a tech talk in January about how exactly our multithreading works, along with some other bits of Hack implementation details -- it's really cool, but hard to grasp without an intro, even if the code is open source!)