Stream: beginners

Topic: ✔ I expected to reach the end of the file, but got stuck ...


view this post on Zulip Rauny (Jun 11 2024 at 06:12):

Hey, noob here. I'm going through the tutorial but got stuck trying to understand why I have this error with the following code:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

import pf.Stdout
import pf.Task

# main : Task.Task {} _
main =
    Stdout.line! "Hello, World!"
    res1 = "test"
    Stdout.line! "Hello, World! $(res1)"
    res2 =
        ["a", "b", "c"]
        |> List.append "d"
        |> Str.joinWith ""
    Stdout.line! res2
    res3 =
        (["a", "b", "c"])
        |> List.append "d"
        |> Str.joinWith ""

but, if I change it to this, it works

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

import pf.Stdout
import pf.Task

# main : Task.Task {} _
main =
    Stdout.line! "Hello, World!"
    res1 = "test"
    Stdout.line! "Hello, World! $(res1)"
    res2 =
        ["a", "b", "c"]
        |> List.append "d"
        |> Str.joinWith ""
    Stdout.line! res2
    res3 =
        (["a", "b", "c"])
        |> List.append "d"
        |> Str.joinWith ""
    Stdout.line! res3

Roc version: roc nightly pre-release, built from commit 0e1a9545c6c on Sat Jun 8 09:11:54 UTC 2024

Any help or explanation is appreciated. Thank you!

view this post on Zulip Brendan Hansknecht (Jun 11 2024 at 06:21):

Fundamentally, basic cli requires that main returns a task.

view this post on Zulip Brendan Hansknecht (Jun 11 2024 at 06:22):

With the first example, the last thing you do is assign a variable instead of returning a task

view this post on Zulip Brendan Hansknecht (Jun 11 2024 at 06:22):

With the second example, you end with a !. ! ends up building up a chain of tasks.

view this post on Zulip Brendan Hansknecht (Jun 11 2024 at 06:23):

So ending with Stdout.line! res3 will return the full chain of tasks, with the last task being printing res3

view this post on Zulip Rauny (Jun 11 2024 at 07:05):

oh ok, it's clear now, thank you so much!

view this post on Zulip Notification Bot (Jun 11 2024 at 07:05):

Rauny has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC