Stream: beginners

Topic: Tutorial


view this post on Zulip Richard Feldman (Nov 22 2021 at 02:03):

I've been working on a tutorial for building Roc applications - I've written maybe like 30% of it, but I wanted to share what I have so far in case it's already useful to people in its current WIP form!

https://gist.github.com/rtfeldman/b5cd8d8876bfcd70cb82caaa55875285

view this post on Zulip Richard Feldman (Nov 22 2021 at 02:03):

also if anyone has any feedback or questions about the sections that are written, please feel free to ask/share here!

view this post on Zulip Anton (Nov 22 2021 at 12:53):

Looking good so far :)
Some corrections:

view this post on Zulip Lucas Rosa (Nov 22 2021 at 16:34):

nice, looks good

view this post on Zulip Yann Simon (Nov 29 2021 at 16:03):

I'm trying out this tutorial, and I have my first error:

Num.toStr 4

── NOT EXPOSED ─────────────────────────────────────────────────────────────────

The Num module does not expose `toStr`:

4│      Num.toStr 4
        ^^^^^^^^^

Am I missing something?

view this post on Zulip Lucas Rosa (Nov 29 2021 at 16:15):

that builtin may be unimplemented, not sure tho, I haven't checked

view this post on Zulip Lucas Rosa (Nov 29 2021 at 16:28):

I think you can use Str.fromInt if you'd like

view this post on Zulip Yann Simon (Nov 29 2021 at 16:32):

Thanks, Str.fromInt works.

view this post on Zulip Yann Simon (Nov 29 2021 at 16:40):

Should I open a PR to change that? Or will Num.toStr be available soon?

view this post on Zulip Tankor Smash (Nov 29 2021 at 17:14):

hey I'm new to rust and roc, and just installed my Win 10 WSL, since native windows isn't supported yet. couldnt run any of the rust/zig/c examples with a brand-new WSL Ubuntu install.

idk how many people this would help but to get the zig and C examples to compile (couldnt get rust yet), I made sure the windows Hyper-V Platform was enabled (or at least clicked once):
image.png

I had to enable SVM on my AMD Mobo via BIOS to allow this at all.

then hit wsl at the powershell cli, to open the store prompt to install Ubuntu https://www.microsoft.com/store/productId/9NBLGGH4MSV6

then followed the ubuntu instructions (setting username etc)

then I needed to

sudo apt update
sudo apt upgrade
sudo apt install build-essentials

because otherwise I couldn't get clang installed without those three things

tar -xf /mnt/c/Users/WINDOWSUSERNAME/Downloads/roc_nightly-linux_x86_64-20211129-673215.tar.gz //downloaded roc through the GH releases
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh //to install roc

The rust example doesn't compile (but ill paste the errors in a bit), but the zig and C ones do:

wget https://ziglang.org/download/0.8.1/zig-linux-x86_64-0.8.1.tar.xz
tar -xf zig-linux-x86_64-0.8.1.tar.xz
sudo ln -s  $(pwd)/zig-linux-x86_64-0.8.1/zig /usr/local/bin/zig

for zig as per docs

sudo apt install clang

for C, as per docs

view this post on Zulip Tankor Smash (Nov 29 2021 at 17:16):

my rust example doesn't compile though (the duplication is part of the output):

RUST_BACKTRACE=1 ./roc examples/hello-rust/Hello.roc
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', compiler/build/src/link.rs:471:39
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14
   2: core::result::unwrap_failed
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/result.rs:1617:5
   3: roc_build::link::rebuild_host
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any { .. }', cli/src/build.rs:223:50
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14
   2: core::result::unwrap_failed
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/result.rs:1617:5
   3: roc_cli::build::build_file
   4: roc_cli::build
   5: roc::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.```

view this post on Zulip Anton (Nov 29 2021 at 17:21):

Hi @Tankor Smash,
Thanks for the detailed report! The rust error is because it could not find cargo. If you installed rust in the same terminal you need to create a new one. Try cargo --version to see if you have it in path.

view this post on Zulip Anton (Nov 29 2021 at 17:24):

I'll update the README to prevent this issue.

view this post on Zulip Lucas Rosa (Nov 29 2021 at 17:28):

Yann Simon said:

Should I open a PR to change that? Or will Num.toStr be available soon?

so we would need a new builtin for this but I think we can just map the name Num.toStr to Str.fromInt

view this post on Zulip Tankor Smash (Nov 29 2021 at 17:30):

@Anton thanks, restarting wsl and running cargo --version displays something, and it compiles (it took about 30s to compile compared to c and zig's 1s, I thought it had broken). thanks!

view this post on Zulip Lucas Rosa (Nov 29 2021 at 17:30):

I can add it later, there isn't much of a learning opportunity with that one otherwise I would suggest we pair on it and I walk you through it. There's other builtins that would have more learning value @Yann Simon

view this post on Zulip Lucas Rosa (Nov 29 2021 at 17:30):

you can leave the tutorial as is and we'll just make sure to add this builtin

view this post on Zulip Anton (Nov 29 2021 at 17:33):

@Tankor Smash nice to have it working :) 30 seconds is a lot indeed, I have not encountered that myself. Perhaps some extra things are done when you build the first rust project on your OS.

view this post on Zulip Anton (Nov 29 2021 at 17:38):

It's possible that was caused by slow internet or bad wifi.

view this post on Zulip Tankor Smash (Nov 29 2021 at 17:40):

Anton said:

It's possible that was caused by slow internet or bad wifi.

yeah it could be. I'm on a gigabit connection, having to download a bunch of crates for the first compile makes sense I guess!

view this post on Zulip Brendan Hansknecht (Nov 29 2021 at 17:46):

Make sure that you are storing files on the linux filesystem and not windows. I know that caused extremely slow builds of roc itself on WSL. So it wouldn't be surprising if it affected all rust projects on WSL.

view this post on Zulip Tankor Smash (Nov 29 2021 at 17:46):

Lucas Rosa said:

that builtin may be unimplemented, not sure tho, I haven't checked

https://github.com/rtfeldman/roc/blob/trunk/TUTORIAL.md#functions-and-if I just got caught on that too lol, I assumed it was a function because of the tutorial too.

view this post on Zulip Tankor Smash (Nov 29 2021 at 18:24):

in roc repl, how do you submit a line?

»addXY = \x, y -> x + y
…
…
…
…``` can't hit enter to submit this. Ctrl+Enter and Shift+Enter doesn't  let me submit either

view this post on Zulip Tankor Smash (Nov 29 2021 at 18:25):

I can type :help and it'll show the help message, but not define functions it doesnt seem like

view this post on Zulip Folkert de Vries (Nov 29 2021 at 18:30):

@Tankor Smash WSL itself is also slow when files need to be moved between windows and linux file systems, and the rust compiler seems to move a lot of files around. My compilation (linux) compilation got way faster with a better SSD. @Brian Carroll may have more details on how to best set up our compiler

view this post on Zulip Folkert de Vries (Nov 29 2021 at 18:30):

on wsl

view this post on Zulip Anton (Nov 29 2021 at 18:42):

Tankor Smash said:

in roc repl, how do you submit a line?

»addXY = \x, y -> x + y



@Tankor Smash the repl only works with expressions for now and expressions have to return something.
So entering addXY 1 2 after your definition would work.
It is also not yet possible to keep values in scope between REPL entries, so every entry starts with a clean scope.

view this post on Zulip Tankor Smash (Nov 29 2021 at 18:46):

Anton said:

Tankor Smash said:

in roc repl, how do you submit a line?

»addXY = \x, y -> x + y



Tankor Smash the repl only works with expressions for now and expressions have to return something.
So entering addXY 1 2 after your definition would work.
It is also not yet possible to keep values in scope between REPL entries, so every entry starts with a clean scope.

ah my mistake, thank you!

view this post on Zulip Lucas Rosa (Nov 29 2021 at 19:46):

ok I'm back, I'm about to add Num.toStr

view this post on Zulip Tankor Smash (Nov 29 2021 at 23:24):

Is there a way to read a file from disk, maybe using a Task or something? I see stdin in the tutorial, but I'm not sure what else

view this post on Zulip Folkert de Vries (Nov 29 2021 at 23:24):

that is something the platform needs to provide

view this post on Zulip Folkert de Vries (Nov 29 2021 at 23:25):

I think there are some experiments with it somewhere, but for now a platform could just read the file as a string/bytes as needed

view this post on Zulip Folkert de Vries (Nov 29 2021 at 23:25):

at some point we'd want file handlers so the whole thing is not loaded into memory

view this post on Zulip Tankor Smash (Nov 29 2021 at 23:28):

I quickly looked through the zig and rust platforms to try and find one, but I'll keep looking. I think examples/hello-world/ is what the tutorials examples/cli became right?

view this post on Zulip Tankor Smash (Nov 29 2021 at 23:31):

ah found a trove of them, https://github.com/rtfeldman/roc/tree/c4f6697536db203fecda1ad17a32773d61652e51/examples, these aren't present in the roc the guide had me install, but I'm sure there'll be something here!

view this post on Zulip Brendan Hansknecht (Nov 29 2021 at 23:34):

The false-interpretter example reads from a file. We should probably make a simple file io platform to help people along.

view this post on Zulip Brendan Hansknecht (Nov 29 2021 at 23:35):

That being said, it reads in small chunks instead of just dumping everything to memory.

view this post on Zulip Lucas Rosa (Nov 29 2021 at 23:51):

The talk I gave on zig showtime walks you through adding a platform function that writes to a file, you could do the same but for reading a file

view this post on Zulip Lucas Rosa (Nov 29 2021 at 23:52):

depends if you want to use zig for the platform or not but in general the concept is the same across Rust, C, or Zig

view this post on Zulip Tankor Smash (Nov 29 2021 at 23:55):

https://www.youtube.com/watch?v=FMyyYdFSOHA

view this post on Zulip Lucas Rosa (Nov 30 2021 at 00:04):

yea that one. you can skip to the demo

view this post on Zulip Richard Feldman (Nov 30 2021 at 00:13):

yeah we should add file I/O to examples/cli for sure!

view this post on Zulip Tankor Smash (Nov 30 2021 at 02:12):

1. Expose callback from platform's Package-Config.roc
    * Defines the Roc signature in the `effects` record
2. Write the native function in the zig/rust/C
    * prefix function name with `roc_fx_`
        * zig example: `pub export fn roc_fx_funcnamehere(name: RocStr) callconv(.C) void {}
3. Wrap the platform's exported native function with a Roc function
    * since it's exposed as `fx.Effect`, it can be accessed within the platform's Roc
    * the platform can then export a function that wraps `fx.Effect`
4. Use in app:
    * In the Roc app, add `imports` the platform's wrapped function

something like this? haven't tried it yet but that seems like the gist from your talk @Lucas Rosa

view this post on Zulip Tankor Smash (Nov 30 2021 at 02:13):

seems like its no longer Pkgconfig.roc

view this post on Zulip Lucas Rosa (Nov 30 2021 at 02:17):

@Tankor Smash yep that’s it

view this post on Zulip Shrikanth Upadhayaya (Nov 30 2021 at 02:48):

Going through the tutorial (on macOS 12/M1) I couldn't get Stdout.line to print anything. I put a couple of debug outputs in the platform code and found out that the str it was getting was empty. Eventually, cribbing notes from the echo example, I got some output with this code:

main =
    {} <- await (Stdout.line "I'm a Roc application!")

    Stdout.line ""

I'm not sure why the await makes it work, but I've tried every permutation possible and this is the only way I got any output :thinking:

view this post on Zulip Shrikanth Upadhayaya (Nov 30 2021 at 02:49):

Another note: After the first await, Stdout.line works without await - so the final line call in there could have any text and it will get printed.

view this post on Zulip Brendan Hansknecht (Nov 30 2021 at 03:02):

You are probably hitting this issue in some form: https://github.com/rtfeldman/roc/issues/2028

view this post on Zulip Lucas Rosa (Nov 30 2021 at 20:01):

Num.toStr -> https://github.com/rtfeldman/roc/pull/2108

view this post on Zulip Martin Stewart (Dec 02 2021 at 15:53):

@Richard Feldman One suggestion for the tutorial. In this section https://gist.github.com/rtfeldman/b5cd8d8876bfcd70cb82caaa55875285#the-app-module-header it's not quite clear to me if every file defines the packages it needs or if only the file containing a main function does that? And if every file defines its own packages, what happens if two files use conflicting package versions?

view this post on Zulip Richard Feldman (Dec 02 2021 at 18:32):

gotcha, thanks! I can clear this up when I write the part about other modules, but the short answer is that you only define that in one module.

view this post on Zulip jan kili (Dec 04 2021 at 17:53):

This tutorial is well-written.

view this post on Zulip Richard Feldman (Dec 04 2021 at 17:54):

thank you! :hearts:

view this post on Zulip jan kili (Dec 05 2021 at 02:37):

I listened to the first half of it via text-to-speech on a walk this morning, and I was surprised at how many code examples joked about toasters... Now I see that the voice app was just attempting to pronounce Num.toStr.

view this post on Zulip jan kili (Dec 05 2021 at 03:27):

Is there a way to split a large Roc module into multiple files?

view this post on Zulip jan kili (Dec 05 2021 at 04:04):

Jan Van Bruggen said:

Is there a way to split a large Roc module into multiple files?

Nevermind, I think I found my answer in an example: https://github.com/rtfeldman/roc/blob/e872d00b1329b69851ba9cc2aa158d1bba96b959/examples/benchmarks/QuicksortApp.roc#L3

importer:

# /.../project/SomeRocFile.roc
...
import [AdjacentRocFile]
...
AdjacentRocFile.someFunction ...
...

importee:

# /.../project/AdjacentRocFile.roc
interface AdjacentRocFile exposes [someFunction] imports []
...
someFunction = ...
...

view this post on Zulip jan kili (Dec 05 2021 at 06:56):

I assume that the trailing asterisk in this: [ A, B ] : List [ A, B ]* ...

  1. is the same as the mysterious asterisk at 21:28 of the A Taste Of Roc video on YouTube, and
  2. represents something about the tag union being "open".

Is that correct?
Is there any documentation on the distinction between "open"/"closed" tag unions? The only references I see to them are not descriptive - once in the tutorial and once in this chatroom.

view this post on Zulip Johannes Maas (Dec 05 2021 at 08:29):

I think what you're looking for is explained in https://github.com/rtfeldman/roc/blob/trunk/roc-for-elm-programmers.md. Search for "unbound".

view this post on Zulip Richard Feldman (Dec 05 2021 at 14:02):

yeah I'm working on adding both to the tutorial! (Other modules and open unions)

view this post on Zulip jan kili (Dec 08 2021 at 14:53):

I have a question about how Task and await work in the example CLI platform: https://github.com/rtfeldman/roc/issues/2151
Any insight appreciated! :)

view this post on Zulip Matthias Devlamynck (Dec 08 2021 at 14:58):

@JanCVanB It's probably a bug, I think you're right it should work.

view this post on Zulip jan kili (Dec 08 2021 at 15:16):

Thanks, that's validating :)

view this post on Zulip Anton (Dec 08 2021 at 15:59):

I believe this is indeed a bug caused by #2028

view this post on Zulip jan kili (Dec 08 2021 at 16:52):

Ah, so it's a compiler bug, not an examples/cli/platform bug?

view this post on Zulip jan kili (Dec 08 2021 at 16:54):

In that case, I'll just start all of my mains with {} <- await once_upon_a_time :yum:

view this post on Zulip Anton (Dec 08 2021 at 17:08):

I think it has to be _ <- await once_upon_a_time.

view this post on Zulip Brendan Hansknecht (Dec 08 2021 at 17:38):

I think both work. I always use {} with await and no arg. I think _ is an unnamed variable and {} is destructuring an empty struct

view this post on Zulip Notification Bot (Dec 08 2021 at 17:52):

Emiliano Bovetti has marked this topic as resolved.

view this post on Zulip Notification Bot (Dec 08 2021 at 17:53):

Emiliano Bovetti has marked this topic as unresolved.

view this post on Zulip Maxwell Bernstein (Dec 11 2021 at 01:50):

Hi all,
I'm running the tutorial code:

app "hello"
    packages { pf: "examples/cli/platform" }
    imports [ pf.Stdout ]
    provides [ main ] to pf

main = Stdout.line "I'm a Roc application!"

with ./target/debug/roc Hello.roc and I get

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', compiler/build/src/link.rs:312:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any { .. }', cli/src/build.rs:223:50
🔨 Rebuilding host... %

What am I doing wrong?

view this post on Zulip Brendan Hansknecht (Dec 11 2021 at 01:55):

Do you have clang installed?

view this post on Zulip Erwin Kuhn (Dec 11 2021 at 01:58):

I think this is the current bug where main can't be a single Stdout.line statement. Maybe try out the solution in #2151 to get main to work?

Edit: I read too fast, it's not that bug. But you'll run into it right afterwards :sweat_smile:

view this post on Zulip Maxwell Bernstein (Dec 11 2021 at 03:02):

Yes but apparently only as clang-12. I will update-alternatives as I did for llvm-as

view this post on Zulip Maxwell Bernstein (Dec 11 2021 at 03:03):

After doing that, it worked! Neat. That is not a very helpful error message :) Let me look at the #2151 now...

view this post on Zulip Maxwell Bernstein (Dec 11 2021 at 03:05):

If I do

app "hello"
    packages { pf: "examples/cli/platform" }
    imports [ pf.Stdout ]
    provides [ main ] to pf

main =
    {} <- await (Stdout.line "hi")
    Stdout.line "yep"

but forget to import Task, I get:

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/mono/src/ir.rs:8228:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Maxwell Bernstein (Dec 11 2021 at 03:06):

Why is it that I have to do one awaited Stdout.line and also one other Stdout.line beneath?

view this post on Zulip Brendan Hansknecht (Dec 11 2021 at 03:11):

Broken effects in Roc. They generally work as expected but they are definitely not running and working as expected under the hood.

view this post on Zulip Ivo Balbaert (Dec 15 2021 at 10:47):

The tutorial is very well written! However it is good it is still private, because a lot of code snippets don't work yet. I think this should be mentioned at the top of the document. There is of course issue #2028 about Tasks, but I have encountered quite a few other problems, on today's version of the compiler. Is it worthwhile to make issues for them? (of course I will make sure that they are not yet reported)
.

view this post on Zulip Richard Feldman (Dec 15 2021 at 11:35):

yes, definitely please make issues for them! Also, don't worry about checking if they're reported or not already - it's easy to sort out duplicates, and it can be useful to get more data when we get different reports from running on different machines!

view this post on Zulip drew (Jan 04 2022 at 01:51):

Hey all. I'm at this spot in the tutorial: https://github.com/rtfeldman/roc/blob/trunk/TUTORIAL.md#building-an-application

view this post on Zulip drew (Jan 04 2022 at 01:51):

i've got what looks to be the correct code in Hello.roc:

view this post on Zulip drew (Jan 04 2022 at 01:51):

$ cat Hello.roc
app "hello"
    packages { pf: "examples/cli/platform" }
    imports [ pf.Stdout ]
    provides [ main ] to pf

main = Stdout.line "I'm a Roc application!"

view this post on Zulip drew (Jan 04 2022 at 01:51):

this is at the source of the Roc tree

view this post on Zulip drew (Jan 04 2022 at 01:51):

however when i run it, i don't get any output!

view this post on Zulip drew (Jan 04 2022 at 01:52):

$ cargo run Hello.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/roc Hello.roc`
🔨 Rebuilding host... Done!

view this post on Zulip drew (Jan 04 2022 at 01:52):

What am I doing wrong?

view this post on Zulip Brendan Hansknecht (Jan 04 2022 at 02:37):

It's a compiler bug

view this post on Zulip Brendan Hansknecht (Jan 04 2022 at 02:37):

Tasks have some issues currently

view this post on Zulip jan kili (Jan 04 2022 at 02:37):

https://github.com/rtfeldman/roc/issues/2151

view this post on Zulip Brendan Hansknecht (Jan 04 2022 at 02:37):

The work around is to await the task

view this post on Zulip jan kili (Jan 04 2022 at 02:38):

Yup, like this:

main =
    _ <- await Stdout.line "Once upon a time..."
    Stdout.line "I'm a Roc application!"

view this post on Zulip jan kili (Jan 04 2022 at 02:39):

(it is currently bugged so that main needs at least one awaited Task to run at all)

view this post on Zulip jan kili (Jan 04 2022 at 02:40):

(in practice, I use an empty string for the first await, and then I have an actually-helpful newline prefix for my output!)

view this post on Zulip drew (Jan 04 2022 at 03:58):

Got it, thanks

view this post on Zulip drew (Jan 04 2022 at 03:59):

so I now have this:

view this post on Zulip drew (Jan 04 2022 at 03:59):

app "hello"
    packages { pf: "examples/cli/platform" }
    imports [ pf.Stdout, pf.Task.{ await } ]
    provides [ main ] to pf

main =
  _ <- await Stdout.line "I'm a Roc application!"

view this post on Zulip drew (Jan 04 2022 at 04:00):

$ cargo run Hello.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/roc Hello.roc`
thread 'main' panicked at 'not yet implemented: unhandled parse error: IndentEnd(@187)', reporting/src/error/parse.rs:545:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip drew (Jan 04 2022 at 04:00):

ah, my indents are off i think

view this post on Zulip drew (Jan 04 2022 at 04:00):

hm, still failing

view this post on Zulip jan kili (Jan 04 2022 at 04:00):

No, it's not that. Your main function doesn't return anything.

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

An await is never the last step of a function

view this post on Zulip drew (Jan 04 2022 at 04:01):

ah, i see. what is roc's unit type?

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

(This is unfortunately a more advanced concept than you may be at in the tutorial, but it's a result of the current bug)

view this post on Zulip drew (Jan 04 2022 at 04:02):

this makes sense, i'm a haskell user so i think i can see the parallel

view this post on Zulip jan kili (Jan 04 2022 at 04:02):

In my example above, I await one stdout task and then return another

view this post on Zulip jan kili (Jan 04 2022 at 04:02):

await is syntax sugar for a callback function, so you now need to add that callback function's body on the next line

view this post on Zulip drew (Jan 04 2022 at 04:02):

does roc have a unit type?

view this post on Zulip drew (Jan 04 2022 at 04:02):

akin to haskell's ()

view this post on Zulip jan kili (Jan 04 2022 at 04:03):

I'm not a Haskeller and idk what a unit type is, but it might be {}

view this post on Zulip jan kili (Jan 04 2022 at 04:03):

(the empty record singleton)

view this post on Zulip drew (Jan 04 2022 at 04:04):

hmm this still fails

view this post on Zulip drew (Jan 04 2022 at 04:04):

app "hello"
  packages { pf: "examples/cli/platform" }
  imports [ pf.Stdout, pf.Task.{ await } ]
  provides [ main ] to pf

main =
  _ <- await Stdout.line "I'm a Roc application!"
  {}

view this post on Zulip drew (Jan 04 2022 at 04:04):

Mismatch in compiler/unify/src/unify.rs Line 1173 Column 13
Trying to unify two flat types that are incompatible: Func([218, 228], 216, 197) ~ Func([102, 103, 109], 111, 112)

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/mono/src/ir.rs:8266:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip jan kili (Jan 04 2022 at 04:04):

Yes, as your pf of choice wants a main that returns a Task

view this post on Zulip drew (Jan 04 2022 at 04:04):

ah, i see, thanks

view this post on Zulip jan kili (Jan 04 2022 at 04:05):

Running cargo check Hello.roc might yield a better error message with the current compiler

view this post on Zulip drew (Jan 04 2022 at 04:07):

── TOO MANY ARGS ───────────────────────────────────────────────────────────────

The await function expects 2 arguments, but it got 3 instead:

6│  main =
                                             ^^^^^

Are there any missing commas? Or missing parentheses?

────────────────────────────────────────────────────────────────────────────────

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

Gah, that's my mistake

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

I forgot to put parens around my example's await arg

view this post on Zulip jan kili (Jan 04 2022 at 04:08):

await (foo bar)

view this post on Zulip drew (Jan 04 2022 at 04:08):

ah, right! it's working now, thanks

view this post on Zulip drew (Jan 04 2022 at 04:08):

so the current bug is that you _must_ have at least one await in main?

view this post on Zulip Brendan Hansknecht (Jan 04 2022 at 04:11):

It's actually a lot bigger behind the scenes, but from the view of most users/applications that is a common manifestation of the bug. A mix of details here: https://github.com/rtfeldman/roc/issues/2028

view this post on Zulip drew (Jan 04 2022 at 04:12):

thanks, reading now

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

And welcome to Roc! :) Happy to have you. Baptism by fire.

view this post on Zulip drew (Jan 04 2022 at 04:13):

yeah, it feels like Tasks need to be closures only, with execution deferred to the runtime. but hey, maybe i'm biased from haskell

view this post on Zulip drew (Jan 04 2022 at 04:13):

thanks :)

view this post on Zulip drew (Jan 04 2022 at 04:13):

i'm fairly sure that purescript implements Effect as a thunk

view this post on Zulip drew (Jan 04 2022 at 04:14):

indeed https://github.com/purescript/purescript-effect/blob/master/src/Effect.js

view this post on Zulip drew (Jan 04 2022 at 04:14):

check out that bind https://github.com/purescript/purescript-effect/blob/985d97bd5721ddcc41304c55a7ca2bb0c0bfdc2a/src/Effect.js#L9-L15

view this post on Zulip Brendan Hansknecht (Jan 04 2022 at 04:16):

Yeah, they should be closures that get returned and then run as a chain. Though can potentially be inlined in some cases.

view this post on Zulip Zeljko Nesic (Jan 04 2022 at 14:37):

drew said:

check out that bind https://github.com/purescript/purescript-effect/blob/985d97bd5721ddcc41304c55a7ca2bb0c0bfdc2a/src/Effect.js#L9-L15

Arrow notation makes it even better! :D

bindE = (a) => (f) => () => f(a())()

view this post on Zulip Richard Feldman (Jan 04 2022 at 18:16):

it feels like Tasks need to be closures only, with execution deferred to the runtime.

yeah, that's what they ought to be; the bug is that sometimes they aren't, even though we want them to be!

There's a WIP fix here: https://github.com/rtfeldman/roc/pull/2226 - but it currently causes regressions in other places.

It's proven to be one of those bugs that's conceptually simple but annoyingly tricky to fix in practice.

view this post on Zulip Richard Feldman (Jan 08 2022 at 01:50):

I have a PR to add a bunch of stuff to the tutorial. Any feedback welcome! https://github.com/rtfeldman/roc/pull/2327

view this post on Zulip Michael (Dec 25 2022 at 09:39):

Taking my first steps in Roc by following the tutorial. Some feedback:
Section "Installation" should refer to the installation guide at https://github.com/roc-lang/roc/tree/main/getting_started

The Install link at the top of the page (in the header bar) points to https://www.roc-lang.org/install which does not exist.

https://github.com/roc-lang/roc/tree/main/getting_started says:
You can run examples as follows:
cd examples
roc run helloWorld.roc

but the tutorial says: run main.roc by using roc dev.
Unclear to me what this means. Should this be "roc main.roc dev"? And why use the dev subcommand here?

view this post on Zulip Luke Boswell (Dec 25 2022 at 10:41):

roc dev myRocAppFile.roc will run your app including expectations and I think other debugging helpful things, it won't run if there are any errors or warnings. I think roc run mayAppMainFile.roc will let you run even if you have warnings.

view this post on Zulip Anton (Dec 26 2022 at 08:48):

Thanks for bringing this to our attention @Michael, I'll fix those issues.

view this post on Zulip Joshua Warner (Dec 26 2022 at 17:28):

I'm trying to wrap my brain around how I can go about splitting up a large roc file into multiple modules, and there doesn't seem to be an existing section in the tutorial about how this works. Is that in the works?

view this post on Zulip Anton (Dec 26 2022 at 17:50):

In the latest version of the tutorial, which is not live yet, there is a subsection for modules with the text: "[This part of the tutorial has not been written yet. Coming soon!]". I don't think anyone is planning on writing that in the short term though.

view this post on Zulip Brian Carroll (Dec 26 2022 at 18:44):

You can make interface modules and import them into your app module. See how examples/virtual-dom-wip/example-client.roc imports ExampleApp.roc

view this post on Zulip Brian Carroll (Dec 26 2022 at 18:47):

Often the best way to split a big file is to find a type that has some associated functions and pull them out into an interface. If you haven't seen it, search on YouTube for "The Life of a File" by Evan Czaplicki. It's about Elm but it applies to Roc too.

view this post on Zulip Joshua Warner (Dec 26 2022 at 19:29):

Thanks!

view this post on Zulip Luke Boswell (Dec 26 2022 at 20:13):

There is a few things like this I'm eyeing to add into the tutorial. I'm away for a few days, but keen to get to this soon. Added an issue to track this.

view this post on Zulip Andreas Pehnack (Feb 15 2023 at 14:44):

I noticed that in https://www.roc-lang.org/tutorial is written in the Records section:
total = addAndStringify { birds, 5, iguanas, 7 }
I guess this should read total = addAndStringify { birds: 5, iguanas: 7 }

view this post on Zulip Anton (Feb 15 2023 at 14:46):

Hi @Andreas Pehnack,
Yes indeed, I'll fix that right now. Thanks :)

view this post on Zulip Ju Liu (Feb 18 2023 at 13:25):

hey there, I noticed that the inline code tags can sometimes be cut across two lines, which makes it harder to read. Do you think it would make sense to make them white-space: nowrap? Screenshot-2023-02-18-at-13.24.40.png

view this post on Zulip Anton (Feb 18 2023 at 14:12):

Sounds good @Ju Liu! Feel free to go ahead with a PR if you want, if not; could you write up an issue for it?

view this post on Zulip Ju Liu (Feb 18 2023 at 15:29):

sweet, PR here: https://github.com/roc-lang/roc/pull/5047

view this post on Zulip Ju Liu (Feb 18 2023 at 19:24):

aha, it took me a while to figure out that pf stands for platform :)

view this post on Zulip Joshua Warner (Feb 18 2023 at 19:29):

Hah; I didn't even consider that that stood for anything.

view this post on Zulip Richard Feldman (Feb 18 2023 at 20:04):

oh yeah, it used to be plat at one point I think haha

view this post on Zulip Ju Liu (Feb 19 2023 at 10:45):

I finished the tutorial yesterday, I'm very impressed by the design choices you've made. :heart:

Some random things I enjoyed:

Some things I found a bit strange:

All in all, had lots of fun :)

view this post on Zulip Brendan Hansknecht (Feb 19 2023 at 16:25):

For True being in the tutorial, that is probably just legacy. It used to be True and False before it became Bool.true and Bool.false. also, given it is free to describe a more specific enum instead of using a bool, it probably is advised to not use a bool a lot of the time. When searching a list, for example, use Found and NotFound instead of true and false. Etc.

view this post on Zulip Brendan Hansknecht (Feb 19 2023 at 16:26):

Also, if you want to just use true instead of Bool.true, you should just need to add the line true = Bool.true.

view this post on Zulip Brendan Hansknecht (Feb 19 2023 at 16:32):

when I read the sections about open/closed records and open/closed tag unions it made me think that it spawns a lot of conditional branches in my head when I'm reading code, and I have to be extra careful about the *. Maybe in practice this is not a problem because the compiler will help you a lot.

For me at least, I rarely think about it when writing code. Not sure what it would be like if i had to read a big project from someone else.

view this post on Zulip Richard Feldman (Feb 20 2023 at 03:34):

awesome, thanks for the feedback Ju! :smiley:

Ju Liu said:

there is quite a bit of delay in the REPL from when I press enter to when I see the result

this is because the repl isn't yet using our development backend or surgical linker, because they aren't feature-complete enough for it yet. If you check out https://www.roc-lang.org/repl you can see it giving responses instantly because @Brian Carroll made the linking and development backend for WASM super fast, and we haven't caught up outside wasm yet :big_smile:

view this post on Zulip Richard Feldman (Feb 20 2023 at 03:35):

although shout-out to @Ahmad Sattar for making a bunch of progress on the dev backend recently!

view this post on Zulip Richard Feldman (Feb 20 2023 at 03:36):

it will be a wonderful day when it's far enough along that we can switch roc repl over to use it :grinning_face_with_smiling_eyes:

view this post on Zulip Nick Hallstrom (Feb 20 2023 at 19:25):

I think the tutorial got messed up somehow. This is what it looks like for me on mobile right now
84920F56-ACC1-43DE-B92A-5D8054EDCA5A.png

view this post on Zulip Anton (Feb 20 2023 at 19:36):

Thanks for reporting this @Nick Hallstrom, I know this was a recent change, that might have caused it. Someone can try to delete that line with the inspection tools in the browser, I'm done for today. I can take a look tomorrow if it's still unsolved.

view this post on Zulip Giacomo Cavalieri (Feb 20 2023 at 20:17):

@Anton I quickly inspected it in the browser and the nowrap seems to be the cause of the problem. There is a quite long code line in the bullet point list of the Open Records and Closed Records section that doesn't get wrapped. Changing the whitespace wrapping back to normal seems to solve the problem

view this post on Zulip Giacomo Cavalieri (Feb 20 2023 at 20:21):

I agree with Ju Liu that the nowrap helps making the tutorial more readable, though. Maybe we could enable the normal wrapping just in the mobile friendly media query?

view this post on Zulip Giacomo Cavalieri (Feb 20 2023 at 20:52):

So I made a quick pull request with a fix for that problem on mobile devices. I hope I didn't mess up since it's my first time making a PR on an open source project :sweat_smile:
https://github.com/roc-lang/roc/pull/5053

view this post on Zulip Anton (Feb 21 2023 at 08:19):

Looks good @Giacomo Cavalieri! Thank you and congratulations on your first open source PR :)

view this post on Zulip Giacomo Cavalieri (Feb 21 2023 at 08:22):

Thanks! I hope I’ll be able to contribute more in the future :)

view this post on Zulip Nick Hallstrom (Feb 22 2023 at 02:14):

What would you guys think about putting an example in the tutorial of backpassing with multiple parameters? It really confused me the first time I saw it, even though it makes perfect sense now. I mean this syntax: a, b <- someFunc “abc”

view this post on Zulip Richard Feldman (Feb 22 2023 at 03:25):

seems reasonable!

view this post on Zulip joaogui1 (Jul 28 2023 at 21:37):

So I was going through the tutorial and accidentally misnamed the greeting variable to greetings, and so when I tried to do the string interpolation it failed and killed the repl
Is that the expected behaviour? Shouldn't the repl be more resilient?

» "\(greeting) there, \(audience)!"
"\xc8\x9d\"\x04\x01"
thread 'main' panicked at 'Roc hit an error', crates/repl_cli/src/cli_gen.rs:134:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Folkert de Vries (Jul 28 2023 at 22:01):

it should, yes. What operating system was this on?

view this post on Zulip Folkert de Vries (Jul 28 2023 at 22:03):

also that line number is different from the main branch at least. How recent is your build of roc?

view this post on Zulip joaogui1 (Jul 28 2023 at 22:34):

it was on a M1 mac
I think my build is at most 1 month old

view this post on Zulip Luke Boswell (Jul 29 2023 at 03:33):

» "\(greeting) there, \(audience)!"
"\xe8\x9d\t\x05\x01"
thread 'main' panicked at 'Roc hit an error', crates/repl_cli/src/cli_gen.rs:142:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is what I get on latest main using M2 mac

view this post on Zulip Anton (Jul 30 2023 at 08:52):

I made issue #5708 for this.


Last updated: Jul 05 2025 at 12:14 UTC