Preparing for Advent of Code 2021

Andrew Fontaine <>

This will be my fourth (😮) year doing the Advent of Code challenges! The first three years, I have attempted the challenges in elixir. I was new to elixir, and (while still an amateur) I’ve grown pretty comfortable with the language. It was fun creating simple OTP processes to handle “communication” between two “computers”, but I felt it was time to strike out and learn something new!

Enter ReScript

I’ve been attempting to build a bot for screeps, off and on, for a few years now. For the unaware, screeps is an MMO RTS that is always playing, and your way of ensuring your creeps continue to work while away is by programming them in JavaScript.

Now… I do JavaScript day in and day out for work, so that wouldn’t have been very exciting. I had initially planned to build it out in TypeScript, but that felt too much like normal JavaScript. Elm started promising, but the more I looked into the ecosystem, the more I realized it really wouldn’t work. Elm seems best designed when working within a browser, where it can run freely and unencumbered. Slapping screeps’ event loop on top of it (the game calls your main function every tick) felt like throwing away some of the power of elm.

Then, I came across bucklescript reason ReScript. ReScript is an alternative syntax for ocaml to make it a little more JavaScript-y, and a lot of tooling to make that syntax compile very nicely to JavaScript. It had all the statically-typed functional goodness of elm, but with a much more general purpose attitude. It was perfect. I started out happy, until hitting wall after wall of JavaScript inter-op problems. It turns out I may have bitten off more than I could chew. I still come back to the screeps project every now and then, but I mostly tinker for a few hours before forgetting about it.

Maybe… caramel?

It did get me thinking about how interesting a language ocaml is, though. It’s got a lot of depth and history, and has inspired a lot of other languages. I had remembered hearing something about a language trying to bring ocaml to the BEAM, erlang’s (and elixir’s) virtual machine. It looked to be a great candidate for this year!

this past weekend to actually check out the language and make sure it would work well within my existing advent of code infrastructure. I already had lovely mix tasks for downloading puzzle input and running solutions, so if Caramel would work with all that, I’d be pretty happy.

It turns out that the maintainer of Caramel hasn’t had the ability to build out a lot of the language. I understand! My own [library] withers on a vine while I find the energy to work on it. I just don’t want to struggle and fight and be missing features I would normally expect to be there and so on and so on. Learning how ocaml works on top of figuring out these problems is enough, and I don’t want to be frustrated with the tooling, too. Maybe next year I’ll have enough of an idea of what I am doing, and can help out!

For now, it looks like the only solution is to turn to the original…


So yeah, in a few day’s time I’ll be doing advent of code in ocaml. I played around with it a bit this weekend to get to a level of infrastructure similar to my mix tasks to get a taste of the language (more to come on that if I am capable). I can download input and have something set up to nicely run solutions, although I think that second one could probably use a bit of work.

For now? It works, and should be able to hit the ground running come Dec. 1, and keep this updated on my progress.

Any other advent of code fans out there? Any ocaml fans with tips? Let me know!

Want to discuss this post?

Reach out via email to ~afontaine/, and be sure to follow the mailing list etiquette.

Other posts