Exploring how Elm can target Web Assembly
Robin Heggelund Hansen May 28
Title sounds interesting, doesn't it? Last week I got this idea into my head that wouldn't leave. And so, I'm announcing ELS.
What's ELS? It's an experimental compiler for a statically typed Lisp which compiles to Web Assembly. As to what ELS actually means... I'm not sure yet, but I'll be sure to let you know once I find a phrase it can be a fitting acronym for =)
I imagine you might be a bit confused at this point. You might even have double checked the title to make sure it actually contains the word Elm, which it does. So why am I talking about Lisp?
Now, a garbage collector will come sometime in the future. So in the meantime, the time of Evan (author of Elm) is better spent on other things.
So what's this ELS thing about?
Well. Even though adding Elm support in the compiler will be a huge effort for potentially little gain (let's be honest, there are better ways to improve Elm than what it compiles to), that doesn't mean that exploring the space is wasted effort. As Evan has said previously: "Code is the easy part."
How should ports work in a WASM world? How should strings work? Would using the future builtin GC be best, or could a language like Elm do better with a custom GC scheme? How do we compile curried functions to WASM? How would the REPL work? Could Erlang like processes be implemented?
There are a bunch of questions to answer, and there is no reason not to explore that space early on. If we're lucky, by the time Elm is ready to target WASM, some of the ground work will be done already.
The big downside is that none of the compiler work I do can be merged into the Elm compiler sometime down the road. But that's fine. This is an experiment, and I don't expect that the code I write is something one would want to re-use anyway.
What I do hope is that the experience I get from this makes it possible for me to assist with porting Elm to WASM in the future. I might even be able to write some modules which Elm can make use of when that happens, like a string library or even a basic garbage collector which can serve as a stop gap until WASM gets a GC of its own.
Can I try it out?
Sure. The code, and instructions for trying it out, are available here.