Caterpillar

Daily Thought - 2024-04-12

< back to list

I think it is a mistake to give a language inherent capabilities, that then might or might not be available on the platform where you actually want to run it. Look at Rust's standard library, for example. It's not available at all on microcontrollers. It is available in WebAssembly, but then some things just don't work (like print!) or you might get an error when using others (like threads). And yet, it is the baseline that most Rust code is written against.

I really like what Roc does instead: Code inherently can't do anything, except pure computation. If it wants to do I/O, anything that relies on platform capabilities, it specifies the I/O primitives it needs as arguments. These I/O primitives are provided by something called a platform, which is basically a framework that runs your application, and you have to pass those primitives on to the libraries you want to use.

As a result, libraries end up much more portable (in principle; I don't know, about the specific implementation in Roc). A library can't just use the filesystem. It can at most expect to use something that looks like a filesystem. As long as what you give it has the correct interface, you can make that do whatever you need. Store "files" in your microcontroller's flash memory, for example, or in RAM.

This is a concept I'm stealing for Caterpillar.

<< previous thoughtnext thought >>