Stream: beginners

Topic: platforms


view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 13:50):

Will/does Roc provide a set of built-in "standard" Platforms? Everything I saw inside examples has the platform alongside it. Are we intending to build / already have binding generators (similar to wasm-bindgen for Rust+JSWasm or zigler for Zig+Elixir) to streamline platform development?

view this post on Zulip Folkert de Vries (Oct 22 2021 at 13:52):

a platform is just a rust/c/zig app. It's unlikely you'd want to expose a raw C api to a roc platform. The whole idea is that the external api is wrapped in a way that is more friendly

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 13:58):

I'm looking at https://github.com/rtfeldman/roc/blob/trunk/examples/hello-rust/platform/src/lib.rs. This is not a "typical" Rust app. This is similar to the situation before wasm-bindgen, when folks wrote webassembly bindings in rust like this: https://dev.to/shritesh/writing-a-brainfuck-interpreter-in-rust-and-webassembly-13f#webassembly. Now it's simply:

#[wasm_bindgen]
pub fn brainfuck(source: String, input: String) -> String {...}

view this post on Zulip Lucas Rosa (Oct 22 2021 at 14:01):

There are two open pull requests for a platform based on SDL and one for a web server that might also give some insight

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:03):

The rust situation is a bit rough because we have to deal with C FFI, which is not hidden at all at the moment. The C FFI turns out to be kind of subtle. We do provide the roc data structures (RocList, RocStr) but even those need to be handled with care

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:04):

so there is room for some macro magic to make the process nicer, but I'm not sure things have crystallized sufficiently to make it worth it to do that now

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:24):

yeah I think binding generators are a good idea at some point, but haven't really thought about the specifics :big_smile:

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

long-term the idea is that application authors get their platforms from the package repo

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

so I just write my app and say platform: rtfeldman/blah and that's it

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

it just feels like another dependency

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

more or less

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:27):

but the package repo doesn't exist yet, so for the moment it's all local filesystem!

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:27):

Are there any in-built platforms right now?

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:28):

no, the plan is not to have any ship with the compiler - with the possible exception of like a "tutorial" one if we have an interactive tutorial built into the editor

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:29):

but I'd like to have all the platforms be sort of on equal footing, give or take author reputation

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:29):

got it. That sounds reasonable.

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:30):

like I wouldn't want someone to think "I have a cool idea for a way to do a CLI platform, but what's the point when everyone's gonna use the builtin one anyway"

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:31):

as opposed to "ok here's the CLI platform made by the people who made the compiler" - it's got that reputation behind it, so it will probably be a safe default choice for anyone, but it's still just another platform in the package repo

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:37):

Agreed. Final question: How does the compiler already know how to compile the current platform examples? I don't see any build scripts or configuration.

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:38):

it's hardcoded for rust/zig/c

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:39):

just looks for host.c/host.zig and builds them, cargo build when it finds a Cargo.toml

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:39):

nice. Thanks.

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:57):

we're planning to move that into user space though! Just haven't gotten to it yet. :big_smile:

view this post on Zulip M.T. (Dec 23 2022 at 22:10):

Hello, love the language - are there any resources where I can learn more about the platform concept in Roc ? I would like to try to make a PoC platform for own use, to see if Roc could be used for my own use-case

view this post on Zulip Brendan Hansknecht (Dec 24 2022 at 00:34):

Currently most platform documentation comes on the form of examples and people.

view this post on Zulip Brendan Hansknecht (Dec 24 2022 at 00:35):

It is still a changing space and not much has been done for documentation.

view this post on Zulip M.T. (Dec 24 2022 at 14:34):

Thanks - I can see some talk about platforms in here, and I will also look at the example code.

view this post on Zulip Brendan Hansknecht (Dec 24 2022 at 15:23):

Feel free to ask any questions you have. I'm sure someone else or I will attempt to answer

view this post on Zulip Christopher Bertels (Jan 30 2023 at 09:50):

Is it possible to use multiple packages and import from multiple platforms in the same app? I seem to trigger an infinite loop in the compiler trying to do so while trying to create a simple custom platform that also uses the basics-cli platform (for things like the Task type). But I might also just be doing this completely wrong :sweat_smile:

view this post on Zulip Christopher Bertels (Jan 30 2023 at 10:08):

OK. I got it working. Looks like I was missing an imports in the interface decl for my test platform. adding imports [pf.Task.{Task}] fixed it I think

view this post on Zulip Anton (Jan 30 2023 at 10:37):

Hi @Christopher Bertels, it's strange that this appears to work, we intend the user to only be able to use one platform. Using multiple roc packages/modules is supported however.

view this post on Zulip Christopher Bertels (Jan 30 2023 at 10:55):

Hm, yeah not sure if what I said is fully correct, here's the code that seems to work so far: https://github.com/bakkdoor/roc-platform-test/ and I think this line fixed my issues: https://github.com/bakkdoor/roc-platform-test/blob/main/src/TestPlatform.roc#L3

view this post on Zulip Christopher Bertels (Jan 30 2023 at 10:56):

This is the example app using both platforms (or rather just packages?! not sure about the right terminology here): https://github.com/bakkdoor/roc-platform-test/blob/main/examples/TestApp.roc

view this post on Zulip Anton (Jan 30 2023 at 11:04):

Oh I see, you are indeed using only one platform (basic-cli), your TestPlatform.roc is what we call an (interface) module.

view this post on Zulip Anton (Jan 30 2023 at 11:11):

We have a detailed explenation of what a platform is here.

view this post on Zulip Christopher Bertels (Jan 30 2023 at 11:15):

Cool thanks! :)

view this post on Zulip Christopher Bertels (Jan 30 2023 at 11:16):

Is there any documentation on interface modules?

view this post on Zulip Christopher Bertels (Jan 30 2023 at 11:26):

Are they just "normal" modules that export functions? Or is there more to them?

view this post on Zulip Anton (Jan 30 2023 at 12:24):

Christopher Bertels said:

Is there any documentation on interface modules?

No, not yet

Christopher Bertels said:

Are they just "normal" modules that export functions?

Yes, that pretty much covers it :)

view this post on Zulip dionysuz (Apr 10 2026 at 18:20):

as a beginner to roc, i want to understand platforms better. is the expectation / end goal that there are just a few "battle tested platforms" that are fairly generic? eg. cli platform, or do we expect a lot of teams to be implementing their own platform?

the reason why i ask is because, to my knowledge platforms are not really "composable", people will just utilize one platform. so i'm curious if we'll see more monolithic platforms that are battle tested and many people use; or perhaps we'll see platform modules (people pick up modules in the platform ecosystem like lego pieces and build their own platforms out of them). for example what if someone wants the battle-tested cli platform features, but also wants the features another platform has for some P2P client software. would we expect the team to author their own platform in-house that composes the two together? the only issue with that is then their fork may diverge from some upstream module.

maybe i'm misunderstanding something here, i hope the general intent of my question comes across. thanks!

view this post on Zulip Luke Boswell (Apr 10 2026 at 20:02):

I think platforms may evolve a little over time to provide fewer lower level primitives like file reading, or TCP/UDP etc and then most of the higher level logic will be in cross-platform packages that can be shared across the ecosystem and become really common.

So in your example with the P2P client I think almost all of that logic should be platform agnostic and so you could use basic-cli, basic-webserver or another platform just as easily.

view this post on Zulip Luke Boswell (Apr 10 2026 at 20:03):

There is a lot of experimentation here for us to try things out though :grinning:

view this post on Zulip Stuart Hungerford (Apr 13 2026 at 01:02):

Is the tutorial for the new compiler compatible with the latest versions of the new compiler? I'm seeing compile errors with the "Reading from stdin" example:

app [main!] { pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.6/2BfGn4M9uWJNhDVeMghGeXNVDFijMfPsmmVeo6M4QjKX.tar.zst" }

import pf.Stdout
import pf.Stdin

main! = || {
    Stdout.line!("What's your name?")
    name = Stdin.line!()
    Stdout.line!("Hello, ${name}!")
}

view this post on Zulip Luke Boswell (Apr 13 2026 at 01:26):

The tutorial must be out of date... this works

app [main!] { pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.6/2BfGn4M9uWJNhDVeMghGeXNVDFijMfPsmmVeo6M4QjKX.tar.zst" }

import pf.Stdout
import pf.Stdin

main! = |_args| { # <-- missing the args argument
    Stdout.line!("What's your name?")
    name = Stdin.line!()
    Stdout.line!("Hello, ${name}!")

    Ok({}) # <-- missing this
}

view this post on Zulip Stuart Hungerford (Apr 13 2026 at 04:11):

Luke Boswell said ...:

That works, many thanks for your answers to my questions (bonus: even in my timezone)

view this post on Zulip Anton (Apr 13 2026 at 08:37):

I have updated the tutorial in PR#9335. Eventually we could use a Roc notebook for the tutorial so we can verify all the code works but we have some more basic things to finish up first :)

view this post on Zulip Lukas Juhrich (Apr 13 2026 at 10:46):

Anton said:

Eventually we could use a Roc notebook

excuse me, but what is a roc notebook? I couldn't find the term in zulip or the web.

view this post on Zulip Anton (Apr 13 2026 at 10:59):

Similar to a jupyter notebook, it's just an idea I had, I have not talked about it much.

view this post on Zulip Anton (Apr 13 2026 at 11:10):

Ayaz did make a Roc notebook kernel a long time ago for the old Roc


Last updated: May 01 2026 at 12:45 UTC