Try Online
Our Playground lets you try ReScript online, and comes with ReScript-React preinstalled.
Quickly Evaluate Code In Terminal
Use bsc -e
:
SH❯ bsc -e 'let add = (x, y) => x + y'
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
function add(x, y) {
return x + y | 0;
}
exports.add = add;
/* No side effect */
You can pipe the output to Node to run it:
SH❯ bsc -e 'let add = (x, y) => x + y; Js.log(add(1, 2))' | node
3
Quickly Compile A Single File
You can compile a file directly via bsc MyFile.res
:
RES// MyFile.res
let rec fib = n => {
switch n {
| 0 | 1 => n
| n => fib(n - 1) + fib(n - 2)
}
}
Js.log(fib(0))
SH❯ bsc MyFile.res
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
function fib(n) {
if (n === 0 || n === 1) {
return n;
} 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 type signatures directly via bsc -i MyFile.res
SH❯ bsc -i MyFile.res
let fib: int => int
Note that this is for quick tests. For real projects, use our build system.
Format Code
SH❯ bsc -format MyFile.res
let rec fib = n => {
switch n {
| 0 | 1 => n
| n => fib(n - 1) + fib(n - 2)
}
}
Js.log(fib(0))
Our editor plugins come with formatting by default.