Stream: beginners

Topic: composability of platforms


view this post on Zulip Calancea Daniel (Jul 06 2023 at 07:26):

As far as I understood about platforms, it is a low-level binding to the running environment, that is written in languages with APIs for platform specific stuff.

Let's assume I want to create a platform for concurrency, the requirement is that I need to be able to allocate memory. Should this assume that I can access/depend on another platform for this specific task, or it will be implemented with memory allocation directly from platform.

view this post on Zulip Hannes (Jul 06 2023 at 07:44):

There was some discussion on a related question fairly recently, I believe that everything in that thread is still accurate.

view this post on Zulip Hannes (Jul 06 2023 at 07:47):

I think a key thing @Brendan Hansknecht said in that thread is that Roc specific packages could be written for different host languages, e.g. if you wanted great concurrency there could be an Elixir package that implemented the memory management for Roc, then writing a new platform using Elixir would be as simple as importing that library and adding some customisations

view this post on Zulip Hannes (Jul 06 2023 at 07:49):

Oh, and to answer your question more directly, an app can only depend on exactly one platform, so your platform couldn't depend on another platform.

view this post on Zulip Brian Carroll (Jul 06 2023 at 09:54):

I think the idea of a "platform for concurrency" doesn't really fit with Roc's concept of platforms. It's not the right level of abstraction to think about. I would expect Roc to have a platform for command line applications, a platform for web servers, a platform for video games, etc. And some of those platforms would implement concurrency as a feature.

view this post on Zulip Brian Carroll (Jul 06 2023 at 09:56):

Currently the most developed platform is basic-cli

view this post on Zulip Calancea Daniel (Jul 06 2023 at 09:59):

This doesn't seem to be any fun, ultimately you will have to rely on concurrency model provided by the language of the platform and all the problems it brings with it. I've asked before about the concurrency in roc and the answer was pointing to implementing it in a platform #beginners > What is the concurrency model .

view this post on Zulip Brian Carroll (Jul 06 2023 at 10:01):

Yes that's right, it's implemented in the platform. But that doesn't mean that it's the only thing the platform does.

view this post on Zulip Calancea Daniel (Jul 06 2023 at 10:12):

It seems I am missing a key factor about how platforms operate. From reading the thread above, platforms are executables running in their own environment and have a communication channel to interact with roc, if that is the case, then a platform cannot add the functionality of concurrency to the roc runtime itself, roc can only delegate such things to the platform.

Now if that is the case, then would it be possible to send asynchronous events between runtimes?

view this post on Zulip Calancea Daniel (Jul 06 2023 at 10:19):

Now that I think about it, it doesn't seem to make much sense, as you cannot pass code to be executed to other platform, so this means roc cannot have a concurrency system in application layer that is not baked into the language.

view this post on Zulip Brian Carroll (Jul 06 2023 at 10:27):

Roc and the platform are separately compiled to object files, and those two object files are linked into a single executable. So there is not really a communication channel, just direct function calls.

view this post on Zulip Calancea Daniel (Jul 06 2023 at 10:29):

Okay it seems a little bit more clear, the comment about elixir package misled me, as elixir runs in a VM and it is not possible to bake it in the same runtime as roc.

Thanks for the help!

view this post on Zulip Brendan Hansknecht (Jul 06 2023 at 15:17):

Roc totally could be used with an elixir based actor platform. The platform would be more than just concurrency, but the base of the platform could be written in an elixir library and shared. That is the closest we get to composable platforms (code sharing in the host language)

Roughly how it could work:

  1. Exilir starts running a single actor.
  2. The actor uses cffi to call into roc.
  3. Roc returns commands to elixir with continuations.
  4. One of the commands tells elixir to spawn a new actor (that actor will also be in a loop from 1 - 2 just with a different continuation)
  5. Other commands could be for sending and receiving messages (roc could set up specific handlers for receiving messages instead of waiting for them to be polled if that is a wanted/supported feature in elixir).

view this post on Zulip Hannes (Jul 07 2023 at 02:27):

Thank you @Brendan Hansknecht, I used Elixir as an example but don't know enough about it to explain the details :sweat_smile:


Last updated: Jul 06 2025 at 12:14 UTC