BT

Bloomberg Open-sources BuckleScript, JavaScript Backend for OCaml

by Sergio De Simone on Mar 22, 2016 |

Recently open-sourced BuckleScript, a JavaScript backend for OCaml, aims to bring OCaml type safe, high performance code to any JavaScript execution engine, Bloomberg say.

BuckleScript, originally released under the name of OcamlScript then renamed to avoid confusion with another project, has been developed at Bloomberg Labs and aims to enable large scale JavaScript programming. According to Bloomberg, this is made possible by combining OCaml’s industrial strength type system with a fast compiler and offline, i.e., compile time optimizer.

BuckleScript was inspired by js_of_ocaml, according to its main authors, but it has different goals. In particular, BuckleScript is designed to help easier integration with existing JavaScript system, which means that it is possible to call a function defined in an BuckleScript from a plain JavaScript module. This is made possible by the fact that each BuckleScript module is translated into an ES6 module, a concept known as separate compilation that is also available in TypeScript, and that no name mangling is used, which also makes it possible to generate debuggable JavaScript.

As an example of that, the following OCaml code:

let sum n =
    let v  = ref 0 in
    for i = 0 to n do
       v := !v + i
    done;
    !v

is translated into:

function sum(n) {
  var v = 0;
  for(var i = 0; i<= n; ++i){
    v += i;
  }
  return v;
}

BuckleScript can in certain cases outperforn carefully implemented JavaScript libraries, Bloomberg’s engineers say. In particular, a BuckleScript implementation of Facebook’s immutable library shows a twofold performance improvement and a drastic reduction in code size.

Still in its early stages, BuckleScript is available both for Linux and Mac OS X, while Windows support is in the workings. Its source code is available on GitHub. It can be also tried out through its web-based REPL.

Rate this Article

Relevance
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
Community comments

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

Discuss
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT