Hey I was looking to understand how the platform works but I'm not able to find the docs https://www.roc-lang.org/tutorial there is any other page where it is explained?
In which sense: How to make a platform/under the hood details? The api a specific platform exposes to Roc developers? other?
There are a couple of super simplified diagrams in the crates README which may help.
Luke Boswell said:
There are a couple of super simplified diagrams in the crates README which may help.
Thanks!
Brendan Hansknecht said:
In which sense: How to make a platform/under the hood details? The api a specific platform exposes to Roc developers? other?
Sorry for the general question, I would like to know what is a platform (a way to interact with a peace of software written in another language?) and also how it works and it is implemented.
I think all what you ask for ahha
So I'll try to give a summary here. Platforms are currently pretty scarcely documented and mostly developed by looking at existing platforms. They just have been a changing target and tooling is still being built up. Hopefully soonish we will have roc glue
working well enought that this stabilizes, but not quite yet.
For starters, Roc is essentially a sandboxed language. By itself, roc can not interact with the system. It is completely pure and has no side effects.
The platform is ultimately the program that calls into Roc and essentially works as a runtime for each Roc application. A platform is made of 2 parts:
When it comes to actual execution. Roc essentially returns a chain of tasks to the platform. The platform then executes the tasks. When the Roc app has to actually run an effect, it tells that to the platform and the platform executes the effect. Then the platform runs a continuation in roc with any data from the effect (like a read line from standard in).
This separation is how we keep roc a completely pure language without a giant runtime. A platform can basically be seen as a thin language runtime. Though they are likely to be very targeted and more like a framework in other languages.
If you want to look at a platform, I would definitely advise looking at any of the platforms in the examples folder. Of course something like hello world will be simpler while the cli app is more full featured.
When it comes to final executable generation. It is easy to think of it as the roc app compiles to a library and then the platform compiles into an executable that use the library.
Hopefully that is a decent base explanation. Feel free to ask any questions you have or areas you would like to be delved into more.
Thanks for explaining this @Brendan Hansknecht. I also saved this to the roc wiki.
Brendan Hansknecht said:
For starters, Roc is essentially a sandboxed language. By itself, roc can not interact with the system. It is completely pure and has no side effects.
The platform is ultimately the program that calls into Roc and essentially works as a runtime for each Roc application. A platform is made of 2 parts:
- The host: A chunk of code that is written in a non-Roc language. It must speak c abi and is responsible for executing the Roc app. It also is responsible for implementing any actual effects that the application has (printing to std out, drawing to the screen, allocating memory, etc)
- The roc api: This is essentialy the interface between the roc app and the platform. It is written in Roc. Can be thin or a full featured library to enhance roc development for the platform
ok I was courius about this runtime stuff because I think this bring a lot of frash ari inside the functional ecosystem. I did stop to use functional language becase interact with anything was painful, but with roc looks like that it is just a platform call.
Ok lets see if I can use them in the advent of code :)
thanks for the good explaination
Vincenzo Palazzo (vincenzopalazzo) has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC