BuckleScript

BuckleScript

  • Docs
  • Try
  • API
  • Community
  • Blog
  • Languages iconEnglish
    • 日本語
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • 中文
    • 繁體中文
    • Help Translate
  • GitHub

›Intro

Intro

  • What & Why
  • Installation
  • New Project
  • Try
  • Concepts Overview
  • Upgrade Guide to v7

Interop

  • Overview
  • Cheatsheet
  • Embed Raw JavaScript
  • Common Data Types
  • Intro to External
  • Bind to Global Values
  • Null, Undefined & Option
  • Object
  • Object 2
  • Class
  • Function
  • Property access
  • Return value wrapping
  • Import & Export
  • Regular Expression
  • Exceptions
  • JSON
  • Pipe First
  • Generate Converters & Helpers
  • Better Data Structures Printing (Debug Mode)
  • NodeJS Special Variables
  • Miscellaneous
  • Browser Support & Polyfills

Build System

  • Overview
  • Configuration
  • Automatic Interface Generation
  • Interop with Other Build System
  • Performance
  • Advanced

Standard Library

  • Overview

Advanced

  • Conditional Compilation
  • Extended Compiler Options
  • Use Existing OCaml Libraries
  • Difference from Native OCaml
  • Compiler Architecture & Principles
  • Comparison to Js_of_ocaml
Edit

Try

Since 5.1.0, you can try bucklescript in a single file or via command line

bucklescript>bsc -i -e 'let id = x => x'
let id: 'a => 'a;

Here -i flags tell the compiler to infer the signature.

bucklescript.github.io>bsc -e 'let id = x => x'
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
'use strict';


function id(x) {
  return x;
}

exports.id = id;
/* No side effect */

You can also compile it directly via bsc test.re.

Suppose you have a file called test.re:

let rec fib (n) = switch n {
    | 0 | 1 => 1;
    | n => fib (n -1) + fib(n-2);
};
Js.log (fib (0));

You can compile it directly via bsc test.re, producing the following output:

bucklescript.github.io>bsc test.re
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
'use strict';
function fib(n) {
  if (n === 0 || n === 1) {
    return 1;
  } else {
    return fib(n - 1 | 0) + fib(n - 2 | 0) | 0;
  }
}
console.log(fib(0));
exports.fib = fib;
/*  Not a pure module */

You can also get the inferred signature directly via bsc -i test.re

let fib: int => int;
Last updated on 4/13/2020
← New ProjectConcepts Overview →