BT

Open-Source OCaml to JavaScript Compiler BuckleScript Hits 1.0

| by Sergio De Simone Follow 14 Followers on Sep 07, 2016. Estimated reading time: 2 minutes |

BuckleScript 1.0 brings almost full compatibility with OCaml features and an improved FFI with the aim of avoiding writing unsafe JavaScript stubs. InfoQ has spoken with Bloomberg’s Hongbo Zhang, BuckleScript creator at Bloomberg.

According to Bloomberg, BuckleScript aims to attempt to solve the problem of building large scale systems in JavaScript by providing:

  • OCaml industrial-strength type safety
  • Dead code elimination to improve performance at the function and module level thanks to the sophistication of OCaml type-system
  • Compile-time optimizations to improve runtime performance
  • Support for both JavaScript and native platforms

In comparison with other existing transpilers for JavaScript, BuckleScript aims to provide faster compilation, readable and compact output code that retains the same module structure as the OCaml source.

InfoQ has spoken with Hongbo Zhang to learn more about BuckleScript present and future.

What concerns brought BuckleScript from its initial release to version 1.0?

Mostly stabilizing the design of FFI and bug fixes. Since BuckleScript generates readable JavaScript code, there wasn’t too much work needed to make JavaScript call OCaml functions. We have spent several months polishing the design of FFI, so that it is easy for users to call JavaScript from OCaml. The goal is taking advantages of OCaml’s expressive type system (with some BuckleScript customized attributes) to model JavaScript library directly without writing any stub code.

These are the major highlights:

  1. BuckleScript supports two calling convention: uncurried (exactly the same as JavaScript) and optimized curried convention (used in Functional programming paradigm).

  2. We managed to model JavaScript FFI in two styles: a functional FFI like PureScript, and an object FFI by using OCaml’s expressive object type system. This allowed us to model JavaScript structural typing rigorously.

  3. We also have built-in support tying JavaScript this keyword semantics.

  4. Some unique features in OCaml like polymorphic variants are used in model event listeners. This gives us very strongly type-safe guarantees compared with TypeScript.

You can find more details about BuckleScript FFI in a presentation we gave at a meet-up.

One recent effort aimed to integrate Reason with BuckleScript. Could you explain how would it work and what advantages it would bring to developers?

Reason is a JavaScript-like front-end syntax for OCaml developed at Facebook by Jordan’s team. Since OCaml’s compiler tool chain is very modular, it is very easy for us to switch the front end from vanilla OCaml to Reason. Note that Reason is more than just syntax. The team behind Reason also worked very hard to improve the tooling of OCaml, like build system, IDE etc. We work very hard together. For example, the design of BuckleScript FFI took a lot of feedback from Reason’s team.

What’s in BuckleScript roadmap?

  1. BuckleScript compiles OCaml to JavaScript. So, we will follow up the recent developments of OCaml, and upgrade to the latest compiler. There are plenty of exciting new features recently landed in OCaml that we will benefit from. For example, Flambda optimizations will make our compiler even faster.

  2. We will work with other teams (inside or outside Bloomberg) to provide more bindings (NodeJS, Electron and React) for BuckleScript.

  3. BuckleScript’s compiler is also compiled into JavaScript, which means users can not only run but also write OCaml/Reason anywhere. We will package everything into a single JavaScript file so users can get started quickly without hitting JavaScript fatigue. At the same time, we will also improve our playground to make it a better web IDE.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

A very interesting read! thank you for this. by Shirley Perkins

I want to invite you to take a look at AngularJS VS. ReactJS survey results: blog.testproject.io/2016/09/01/front-end-develo...

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT