Philip2: an Elm-to-ReasonML compiler

Paul Biggar
Jan 3 · 2 min read
Some cut down Elm trees

In November, Dark made a decision to move off of Elm, and port our frontend to Bucklescript (aka OCaml, dba ReasonML). Being over 10kLOC, and having active development, it would have been error prone and difficult to port it manually. Instead, we wrote an Elm-to-OCaml compiler to translate it semi-automatically, and then worked to get it over the line manually.

Philip2 (pronounced fee-leap-the-second) is our compiler from Elm to Bucklescript. It parses Elm using elm-format, translates that into the OCaml abstract syntax tree, then uses the OCaml compiler to print out OCaml. We specifically target Bucklescript, and the result plays very nicely with bucklescript-tea, an Elm Architecture for Bucklescript.

Bucklescript translates OCaml to Javascript, and is commonly used in the ReasonML ecosystem. Since Elm is mostly a subset of OCaml — though with a different syntax — it was fairly straightforward to translate it.

The conversion using philip2 removed several weeks of grunt-work to convert the code over to Bucklescript. It still took several weeks of engineering time to finish the conversion, including:

We have a guide to help you port your project, and we will accept contributions to make the process easier and more automated. Using our tools should shave a few weeks off the translation.

We hope this tool will be useful for people looking for an exit strategy from Elm, as well as those looking to try out Elm and worried about it not working out.

Try it!

Darklang

Updates on and from Dark — darklang.com

Paul Biggar

Written by

Tech entrepreneur, software engineer. Founder of Dark: https://darklang.com. Founder of CircleCI. Lover of chocolate and pastries.

Darklang

Darklang

Updates on and from Dark — darklang.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade