Why Bucklescript?

Different things. :slight_smile:

Bucklescript is just a backend to the OCaml compiler that outputs javascript instead of native code.

Reason is just a new syntax that adds on to the OCaml compiler (but you can still use OCaml’s syntax too).

Bucklescript by itself will just compile OCaml to javascript.

Reason by itself will just compile to native code through the OCaml compiler (it is just a plugin to the compiler that lets the compiler understand ‘re’ files in addition to ‘ml’ files).

Reason + Bucklescript will compile reason and ocaml code to javascript.

That can be mixed and matched as you wish.

OCaml has a TON more PPX’s too that can be mixed and matched with the above as well. It is a very powerful compiler, almost trivially easy to extend. Think of PPX’s on the OCaml compiler as being an Elixir-like Macro system on OCaml, except it is even more powerful as it can not only translate ‘other’ code to OCaml, but can also translate OCaml to other things, like javascript. ^.^

It is the current and most advanced incarnation of the old set of (S)ML languages. They are strongly typed, fast to compile, the compiler tries its best to catch as many of your programming issues as it can at compile-time compared to run-time. As an example OCaml can compile at or near the speed of C++, while having substantially shorter and more readable code. ^.^

It is used heavily in a few areas, oddly enough Facebook is a big company that uses it extensively, they’ve released a lot of tools and libraries that were built in OCaml. The biggest user of OCaml is easily JaneStreet though, they’ve practically shaped the entire OCaml ecosystem over the past decade, moving it forward and in to the modern age, that is how OCaml is still so powerful and fast nowadays including giving it the very hex-like opam library manager.

Basically if you want to write in a language that catches most of your programming issues, is dang-fast, and is easy to read and write, that is what OCaml is built for. Optimized C++ can still outperform OCaml sure, but it is within a magnitude of difference, far better than near any other language out that is not something as low-level as C++.

2 Likes