Stream: ideas

Topic: Improving the examples (beginners opinions welcome!)


view this post on Zulip Brendan Hansknecht (Feb 12 2022 at 05:40):

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....

view this post on Zulip jan kili (Feb 12 2022 at 05:41):

Haha I was just about to suggest something similar

view this post on Zulip jan kili (Feb 12 2022 at 05:42):

examples/
    ...
    hello-world/
        apps/
            HelloC.roc
            HelloRust.roc
            HelloWeb.roc
            HelloZig.roc
        platforms/
            hello-c/
                ...
            hello-rust/
                ...
            hello-web/
                ...
            hello-zig/
                ...
    ...

view this post on Zulip Brendan Hansknecht (Feb 12 2022 at 05:43):

I like it except that Hello*.roc will all be exact duplicate files bar the platform line.

view this post on Zulip jan kili (Feb 12 2022 at 05:43):

I like that this would newly demonstrate that platform dirs can be named whatever you want.

view this post on Zulip jan kili (Feb 12 2022 at 05:44):

I like it except that Hello*.roc will all be exact duplicate files bar the platform line.

That can be a fun learning step - try switching the platform!

view this post on Zulip Brendan Hansknecht (Feb 12 2022 at 05:45):

Yeah, maybe just make one Hello.roc with commented out lines for the other platforms.

view this post on Zulip jan kili (Feb 12 2022 at 05:45):

platform "../platforms/hello-rust" # Try changing this to a different Hello World platform!
...

view this post on Zulip Brendan Hansknecht (Feb 12 2022 at 05:45):

Yeah, now I like this

view this post on Zulip jan kili (Feb 12 2022 at 05:47):

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.

view this post on Zulip jan kili (Feb 12 2022 at 05:49):

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.

view this post on Zulip jan kili (Feb 12 2022 at 05:52):

Should the "top-level" subdirectories all be logical groupings?

examples/
    algorithms/
        ...
    benchmarks/
        ...
    hello-world/
        ...
    interactive/
        ...
    some-other-grouping-im-forgetting/
        ...

view this post on Zulip jan kili (Feb 12 2022 at 05:53):

That would help guide newcomers' eyes, as well as enabling veterans to add lots of examples without bloating the "top level"

view this post on Zulip Philippe (Feb 12 2022 at 17:54):

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?

view this post on Zulip Anton (Feb 12 2022 at 18:27):

@Philippe Hosey-Vinchon I think creating a separate repo is best in that case, have fun :)

view this post on Zulip Philippe (Feb 12 2022 at 18:28):

:) ok

view this post on Zulip jan kili (Feb 12 2022 at 18:33):

Yeah, there's a variety of places to put Roc code:

view this post on Zulip jan kili (Feb 12 2022 at 18:35):

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?

view this post on Zulip jan kili (Feb 12 2022 at 18:37):

(It could also provide healthy organic pressure on the feature roadmap, to achieve cleaner solutions.)

view this post on Zulip Anton (Feb 12 2022 at 18:43):

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.

view this post on Zulip jan kili (Feb 12 2022 at 18:56):

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)

view this post on Zulip jan kili (Mar 04 2022 at 13:37):

I've finished a second pass at this reorganization, feedback welcome! https://github.com/rtfeldman/roc/pull/2470

view this post on Zulip jan kili (Mar 04 2022 at 15:36):

Summary: combines helloworlds, algorithms, and interactives into 3 multi-platform directories

view this post on Zulip jan kili (Mar 04 2022 at 15:36):

Screen-Shot-2022-03-04-at-8.29.38-AM.png

view this post on Zulip jan kili (Mar 04 2022 at 15:37):

Is this intuitive?

view this post on Zulip Johannes Maas (Mar 04 2022 at 15:41):

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:

view this post on Zulip jan kili (Mar 04 2022 at 15:41):

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)

view this post on Zulip Folkert de Vries (Mar 04 2022 at 15:45):

could we make zig the default one here? it is generally the fastest, and has the most debug stuff in place

view this post on Zulip jan kili (Mar 04 2022 at 15:46):

@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 :)

view this post on Zulip jan kili (Mar 04 2022 at 15:52):

(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

view this post on Zulip Brendan Hansknecht (Mar 04 2022 at 17:30):

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.

view this post on Zulip Brendan Hansknecht (Mar 04 2022 at 17:30):

I think the task chain breaks tail recursion sadly.

view this post on Zulip Brendan Hansknecht (Mar 04 2022 at 17:32):

That or it was a form of nested tail recursion that cause the problem. As in A -> B -> A instead of A -> A

view this post on Zulip Richard Feldman (Mar 04 2022 at 18:15):

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

view this post on Zulip Folkert de Vries (Mar 04 2022 at 18:17):

yes but it's less convenient for us

view this post on Zulip Folkert de Vries (Mar 04 2022 at 18:17):

so for now...

view this post on Zulip Richard Feldman (Mar 04 2022 at 19:15):

well but we know to access the zig one, right? :big_smile:

view this post on Zulip Richard Feldman (Mar 04 2022 at 19:15):

I'm mainly thinking about the experience of someone brand new to the repo who goes straight to hello world and starts poking around

view this post on Zulip Folkert de Vries (Mar 04 2022 at 19:16):

maybe I misunderstood? it looked like there is just one Hello.roc file

view this post on Zulip Folkert de Vries (Mar 04 2022 at 19:16):

where you have to switch comments around to change platforms

view this post on Zulip jan kili (Mar 04 2022 at 19:17):

There is that, and there's also a hello app for each language, in the platform subdirs

view this post on Zulip Folkert de Vries (Mar 04 2022 at 19:17):

ah, ok

view this post on Zulip Folkert de Vries (Mar 04 2022 at 19:17):

nvm then

view this post on Zulip jan kili (Mar 04 2022 at 19:17):

Okay, I'll change it back to C (done)

view this post on Zulip Philippe (Mar 04 2022 at 20:08):

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.

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:19):

That's certainly feasible but it's quite a long way off right now.

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:19):

The online REPL uses the WebAssembly development backend rather than the LLVM backend, and it's at an earlier stage of development

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:22):

But if you're interested in contributing to the Wasm backend we could use the help!

view this post on Zulip jan kili (Mar 04 2022 at 20:56):

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?

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:57):

What do you mean necessary?

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:57):

It was a demo on a web page

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:57):

You can build wasm from any language you like but you need JS to connect it up to the HTML

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:58):

So that's mainly what it's doing

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:58):

The JS is the point of that platform

view this post on Zulip Brian Carroll (Mar 04 2022 at 20:59):

host.js

view this post on Zulip jan kili (Mar 04 2022 at 21:01):

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/*)

view this post on Zulip Brian Carroll (Mar 04 2022 at 21:01):

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

view this post on Zulip Brian Carroll (Mar 04 2022 at 21:02):

oh ok

view this post on Zulip Brian Carroll (Mar 04 2022 at 21:04):

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

view this post on Zulip jan kili (Mar 04 2022 at 21:07):

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/?

view this post on Zulip jan kili (Mar 04 2022 at 21:07):

I can take this to PMs if you'd like :)

view this post on Zulip jan kili (Mar 05 2022 at 02:54):

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)

view this post on Zulip jan kili (Mar 05 2022 at 03:03):

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)

view this post on Zulip jan kili (Mar 05 2022 at 11:05):

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