could we do examples/hello-wold/app-zig.roc and then examples/hello-world/platform-zig/... and same for the other languages...except not exactly that cause I don't quite like it....
Haha I was just about to suggest something similar
examples/
...
hello-world/
apps/
HelloC.roc
HelloRust.roc
HelloWeb.roc
HelloZig.roc
platforms/
hello-c/
...
hello-rust/
...
hello-web/
...
hello-zig/
...
...
I like it except that Hello*.roc will all be exact duplicate files bar the platform line.
I like that this would newly demonstrate that platform dirs can be named whatever you want.
I like it except that
Hello*.rocwill all be exact duplicate files bar the platform line.
That can be a fun learning step - try switching the platform!
Yeah, maybe just make one Hello.roc with commented out lines for the other platforms.
platform "../platforms/hello-rust" # Try changing this to a different Hello World platform!
...
Yeah, now I like this
Great, so the primary insight here is that the boundaries between /examples/**/ sub-directories can be blurred - apps/ & platforms/ sub-sub-directories enable logical groupings.
I expect that to encourage more app/platform contributions to the /examples/, rather than seeming like an entire new /examples/**/ subdirectory must be added at a time.
Should the "top-level" subdirectories all be logical groupings?
examples/
algorithms/
...
benchmarks/
...
hello-world/
...
interactive/
...
some-other-grouping-im-forgetting/
...
That would help guide newcomers' eyes, as well as enabling veterans to add lots of examples without bloating the "top level"
I was about to look at doing the advent of code (at least just the start) in Roc.
Instead of creating my own repo, should I create a new "grouping" for it?
@Philippe Hosey-Vinchon I think creating a separate repo is best in that case, have fun :)
:) ok
Yeah, there's a variety of places to put Roc code:
examples/ dir is good for learning and experimentingexamples/ dir is for all official educational examples of Roc code That said, it could be very educational to have an official examples/advent-of-code-2021/ dir, to showcase practical code in idiomatic style! What do others think of a crowdsourced+vetted set of AoC21 solutions?
(It could also provide healthy organic pressure on the feature roadmap, to achieve cleaner solutions.)
One thing I'm thinking of is that examples should be diverse and a lot of AoC stuff would be pretty similar.
I feel it would be good to link to projects using roc in the readme and include the AoC repo there.
That's true - I think the example groups should be diverse relative to each other, but I'm fine with similarity within a group (like how benchmarks or CLI are right now, for example)
I've finished a second pass at this reorganization, feedback welcome! https://github.com/rtfeldman/roc/pull/2470
Summary: combines helloworlds, algorithms, and interactives into 3 multi-platform directories
Screen-Shot-2022-03-04-at-8.29.38-AM.png
Is this intuitive?
That's a very helpful organization. Much easier to discover different kinds of examples. I'm already curious to have a closer look at the "interactive" ones. :wink:
New hello_world.roc example:
app "hello_world"
packages { pf: "c-platform" }
# To switch platforms, comment-out the line above and un-comment one below.
# packages { pf: "rust-platform" }
# packages { pf: "swift-platform" }
# packages { pf: "web-platform" } # See ./web-platform/README.md for special instructions.
# packages { pf: "zig-platform" }
imports []
provides [ main ] to pf
main = "Hello, World!"
(Edited to make Zig the default)
(Edited to make C the default again)
could we make zig the default one here? it is generally the fastest, and has the most debug stuff in place
@Brendan Hansknecht I had no idea that you'd implemented a full interpreter for another language in Roc! The false-interpreter/ was fun to read through :)
(Side note, GitHub just added a beta feature for a PR file tree view! I love it)
Screen-Shot-2022-03-04-at-8.51.33-AM.png
Yeah, it was fun to write. Will be much nicer once we have byte byte literals and boxing. Then it shouldn't stack overflow anymore. The main iterations will be a while loop in rust instead of the current recursive version that roc doesn't know how to make tail recursive.
I think the task chain breaks tail recursion sadly.
That or it was a form of nested tail recursion that cause the problem. As in A -> B -> A instead of A -> A
could we make zig the default one here? it is generally the fastest, and has the most debug stuff in place
I went with C for the host because I think the most people know C
yes but it's less convenient for us
so for now...
well but we know to access the zig one, right? :big_smile:
I'm mainly thinking about the experience of someone brand new to the repo who goes straight to hello world and starts poking around
maybe I misunderstood? it looked like there is just one Hello.roc file
where you have to switch comments around to change platforms
There is that, and there's also a hello app for each language, in the platform subdirs
ah, ok
nvm then
Okay, I'll change it back to C (done)
How hard would it be to make those available on the online repl?
It would be a good experience to see a list of examples, click on one, modify a line or two, and execute it.
That's certainly feasible but it's quite a long way off right now.
The online REPL uses the WebAssembly development backend rather than the LLVM backend, and it's at an earlier stage of development
But if you're interested in contributing to the Wasm backend we could use the help!
Related, @Brian Carroll is the hello-world/web-platform necessary? Could hello_world.roc build for wasm using any other (zig, rust, c, swift) platform?
What do you mean necessary?
It was a demo on a web page
You can build wasm from any language you like but you need JS to connect it up to the HTML
So that's mainly what it's doing
The JS is the point of that platform
host.js
Sorry, I wasn't clear - after this proposed refactor, there are two folders, examples/hello-world/web-platform (previously examples/hello-web/platform) and hello-world/website (previously some of examples/hello-web/*)
Sorry I'm typing too quickly, it might sound wrong! :laughing:
When I asked what you meant by necessary I was wondering what are we considering necessary or not? I know you're doing some cleanup around that.
So to show web capability we need some JavaScript, there's not really any way aronud that
oh ok
OK I haven't really been following the conversation around this too closely so I don't really know the thinking behind this split or why it doesn't fit in this case
What I'm really asking is, should it be possible (on trunk) for examples/hello-web/Hello.roc to run on another platform like examples/hello-zig/platform/?
I can take this to PMs if you'd like :)
Brian confirmed that examples/hello-world/web-platform/ is necessary and can't be combined with examples/hello-world/zig-platform. Therefore, I'm going to re-combine examples/hello-world/web-platform/ and examples/hello-world/website/. Thanks, Brian!
(Edit: Done, re-combined)
One thing he taught me in our PM chat was that any given platform is either designed to run on OSes or on wasm (not just whichever of those two a Roc app developer wishes to target at compile time, which is how I thought it worked)
Any objections to the new organization? https://github.com/rtfeldman/roc/pull/2470
If not, I'm ready to merge it and proceed to considering other improvements.
Last updated: Jun 16 2026 at 16:19 UTC