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;