Executing Code In The Playground

Hello, just a suggestion, if would awesome if we could execute code in the playground, not merely translate to JS. So beginners (like me) could visit the playground more often and play around with toy problems before transitioning to more advanced use.

The TypeScript playground also doesn’t have the option to execute, but it generates pure code (as far as I know) which I can copy paste to e.g. JSFiddle very easily. But the ReScript generated code often contains calls to foreign libraries. Or is there some one liner to import e.g. in JSFiddle exactly the function used in generated JS code?

1 Like

Agree, this would be great!

As far as I’m aware (as far as basic execution goes), it does. :slightly_smiling_face:

You’re right :slight_smile:

If you add some imports, you can execute the code in JSFiddle. The most important one is the runtime (rescript-std). e.g.:

import * as Curry from "https://cdn.skypack.dev/@rescript/std@10.1.4/lib/es6/curry.js";

You probably also need React:

import * as React from "https://esm.sh/react@18.2.0";
import * as JsxRuntime from "https://esm.sh/react@18.2.0/jsx-runtime";

Here is the playground example with es6 modules:

EDIT: And I guess the playground output will happen in the not so far away future: Playground output result by diogomqbm · Pull Request #420 · rescript-association/rescript-lang.org · GitHub

1 Like

Thanks a lot! When I compare something like arrays in ReScript, I get Caml_obj in the output. Where can I get this from?

Like Curry above:

import * as Caml_obj from "https://cdn.skypack.dev/@rescript/std@10.1.4/lib/es6/caml_obj.js";

just exchange the ./stdlib from the import in the playground with https://cdn.skypack.dev/@rescript/std@10.1.4/lib/es6