https://github.com/roc-lang/roc/pull/8031
I've made a WASM playground to experiment with. I wanted to be sure we could build for the browser. and figured I'd have some fun with it. It doesn't do much other than compile a single file and show the diagnostics/tokens/AST/CIR (types are a little broken). I haven't really looked closely at the code -- it's a very rough draft.
If we would be open to having something like this include in the repo, I don't mind modifying it. My idea was to have something minimalistic or simple that demonstrates how to build for WASM and integrate with the browser.
Interested to know what people think?
Dope!
yeah please do put it in the repo! :smiley:
let's plan to have it on the website
Would be nice to encode content in url
It already looks great :)
Kiryl Dziamura said:
Would be nice to encode content in url
yeah this would be sweet because then we don't need a server to make these shareable
seems hard to find reliable sources on it, but this post suggests 32K maximum URL length - https://medium.com/@python-javascript-php-html-css/recognizing-the-maximum-url-length-for-different-browsers-ff275903b970
my first thought was gzip->base64
that could work! I'm not sure how well gzip compares to original after paying for base64 though :shrug:
from what I remember it's comparable with the original
but lz77 is great for text so I expect it would work pretty good. anyway, will check how ts playground does it
if (location.hash.startsWith("#code")) {
const code = location.hash.replace("#code/", "").trim()
let userCode = lzstring.decompressFromEncodedURIComponent(code)
// Fallback incase there is an extra level of decoding:
// https://gitter.im/Microsoft/TypeScript?at=5dc478ab9c39821509ff189a
if (!userCode) userCode = lzstring.decompressFromEncodedURIComponent(decodeURIComponent(code))
return userCode
}
well, they use the lzstring method:
so it's a bit fancier than base64
cool!
they use base65 (65 chars in the alphabet) :smile:
if we fully control parsing of the hash fragment, we can afford base81:
A-Z a-z 0-9 - _ . ~ ! $ & ' ( ) * + , ; = : @ / ?
I've been thinking about what the next step for our playground might look like.
I'm wondering if we should consider integrating something like Monaco or CodeMirror instead of just using a textarea. I think this means we can provide syntax highlighting and type hints on hover etc.
Interested to know what people think or if there are any ideas out there.
yeah I do think we should do that
I very much want to avoid using npm for anything
ideally no package.json anywhere in the whole repo :stuck_out_tongue:
(I know we have one for Checkmate right now, but that's obsolete and won't survive the transition to the Zig compiler)
so if there's a way to get those features without npm, I'm all for it!
We could use a CDN build of codemirror, or build one ourselves locally, and vendor the minified js I guess.
yeah vendoring sounds good :thumbs_up:
grab a pre-bundled/minified version
or just bundle/minify it once - I think CodeMirror is the modular one, right? where you use different files to specify which features you want
I'm not 100% -- I figure I'd set something minimal up locally with everything we needed then build a release using Parcel or something and use that. I imagine we want to DCE things and I assume tooling would do that for us.
My web experience is very limited though
that seems fine - would also be fine to put it in a separate roc-lang repo I suppose
and then we just do releases from there and vendor the compiled asset
Hi :)
Is the playground live somewhere? I'm curious to try it
Not live... but easy to spin up. zig build playground then serve the files in ./zig-out/playground
I usually do zig build && simple-http-server -i -nocache ./zig-out/playground
Very cool. Nicely done.
Ok, I've published the playground to a GH Pages site
https://roc-lang.github.io/roc-playground/
The compiler is still very much a WIP, but I wanted to share with everyone here working on the new compiler. It's already super helpful for exploring the new syntax and finding issues.
If you have ideas to improve it please make a PR to this repository :smiling_face:
The WASM asset is hardcoded, we can setup something in CI I guess to build that and update. I figured I'd leave that for a future PR -- if anyone is interested.
Just pushed an update https://roc-lang.github.io/roc-playground
If you check it out, can you try and break it and let me know. Trying to flush out bugs or issues.
Minor annoyance, though that might be not playground related: Loading the playground you start with a comment. When removing a character from that comment there's an error that you should start with a module header. I can see that as useful if I'd had written code before doing that. But not necessarily for me still writing comments :D
What do you think about changing the default to be a minimal roc module. Something like this?
module [add]
add = |a, b| a + b
FYI the hello world, functions, and pattern matching examples you can click at the bottom all show up with errors - not sure if this was an accident or intentional to show the playground editor features, but I might suggest not having the hello world example have an error in it? I feel for that to be there on the simplest example, it gives the impression that things are really broken, for someone coming to the page for the first time.
all show up with errors
Yeah, it's using the new compiler which is still a work in progress
Pushed an update https://roc-lang.github.io/roc-playground/
Again... if people find any issues please let me know :smiley:
Is it expected that the samples on the bottom (e.g. the functions and pattern matching ones) contain "problems" for now?
Yea -- the compiler is very much a WIP and I've included things more to show the 0.1 syntax. As the features get implemented these errors have been rapidly dissapearing :smiley:
Last updated: Jun 16 2026 at 16:19 UTC