I Am Writing a JavaScript to Rust Transpiler in Haskell, So Please Just End My Suffering

Julian Rosenblum
2 min readJan 13, 2017

--

Most people can agree that JavaScript was the most important language of 2016 and will continue to be a staple of the Hacker community for years to come. However, more and more people are talking about Rust. Its C-like semantics combined with guaranteed type-safety give it a unique and important place in programming languages today. And so, I am creating a JavaScript to Rust transpiler in Haskell, a great language for compilers and a great keyword for any Hacker News post. In writing this transpiler, I hope to change the way we think about JavaScript and Rust, and also put an end to the godforsaken monotony of reading about programming languages day after fucking day.

One obvious initial challenge in solving this problem is resolving some of the fundamental incompatibilities of the two languages. Since JavaScript is weakly-typed and has a penchant for undefined behavior, this raises a question of how we should handle behavior in JavaScript that is antithetical to the same patterns that make Rust such a desirable language. If I implement a safe subset of JavaScript, will that free me from my curse of exerting large amounts of energy arguing over React anti-patterns on the internet? If I make use of the unsafe features of Rust to allow for a full ES6/ES2015 implementation, will I be able to have conversations with normal human beings again? Will I be able to feel? If you cut me, will I bleed?

Every morning, I wake up, drink a glass of Soylent and recite the following: “Today, I will solve challenging problems. Tomorrow, I will also solve challenging problems. Every day, I will solve challenging problems, and then the robots will take over, and I will die a fulfilled man, and someone will post my obituary on Hacker News.” Then I log into my machine using a custom startup script.

> Welcome, Julian. Would you like to make the world a better place today? y/n

y

> Very good. You may now enjoy root access to your system.

Haskell offers a number of features that make it an excellent choice for writing a compiler. Although a compiler is typically written in either the source or target language, neither JavaScript nor Rust offers the full richness of Haskell’s recursive algebraic data types. It also makes sense to use a purely functional language to write a compiler, since a compiler is at its core a series of transformations that can and should be done in an elegant, stateless way.

I see clouds in the sky, and green grass. It has been fifty years and I am sitting in the park with my dog, feeding ducks and watching the local children at play. I haven’t uttered the phrase “type-safety” in years. All the startups are gone. I am free.

In conclusion, this is an ambitious project, but I am grateful for all the enthusiasm I’ve received from the JavaScript, Rust, and Haskell communities, as well as the greater compilers community. Be on the lookout for a stable release soon.

Please save me.

--

--