Caterpillar

Daily Thought - 2024-09-05

< back to list

The Caterpillar compiler handles errors in a way that is uncommon: If it encounters an error, it does not stop compilation. Instead it includes the error in whatever representation it's currently generating and moves on. For example, an unresolved identifier results in a special fragment, which then gets compiled into an instruction that triggers the respective error at runtime.

I didn't come up with this. I believe Roc is doing it too. Or at least Richard Feldman talked about this technique on his podcast. There are good reasons for doing it like this. While working on something, you might still want to run your tests, or check something in the debugger, even if some unrelated piece of code doesn't currently typecheck.

In Caterpillar specifically, an intermediate representation is also the basis for what's shown in the debugger (and maybe later, a custom editor?). This allows it to show an enriched form of the code, based on all the information that the compiler has figured out. It would be very inconvenient, if the tooling couldn't show any of your code, just because something in it is broken.

<< previous thoughtnext thought >>