Hi! I am giving roc a try with the day1 of advent of code. I wanted to do a sort of "Hello World" and come up with the following code
app "day1"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.1.1/zAoiC9xtQPHywYk350_b7ust04BmWLW00sjb9ZPtSQk.tar.br" }
imports [pf.Stdout, pf.Task.{ Task }, pf.File, pf.Path,]
provides [main] to pf
parse = \strs ->
List.map strs (\str -> Int.fromStr str)
main =
path = "d1p1.txt"
task =
lines <- File.readUtf8 path |> Task.await
parsed = parse (Str.split lines "\n")
Stdout.line "Hello"
Task.attempt task \res ->
when res is
Ok {} -> dbg "Ok"
Err err -> dbg err
I am aware some of the functions might not exists like Str.split
or Int.fromStr
I was just trying out stuff and see which functions might exists or not. Instead I am getting a Rust panic
thread 'main' panicked at 'not yet implemented: unhandled parse error: Dbg(Continuation(IndentEnd(@542), @542), @534)', crates/reporting/src/error/parse.rs:576:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
If I move code around the panic goes away but it still doesn't compile, and I get errors like the following
9│ main =
10│ path = "d1p1.txt"
11│ task =
12│ lines <- File.readUtf8 path |> Task.await
13│ parsed = parse (Str.split lines "\n")
^
This definition is missing a final expression. A nested definition
must be followed by either another definition, or an expression
x = 4
y = 2
x + y%
Is it an indentation error? I am missing some return value from main? Thanks for the language and for the help!
Can you post the full reordered code that gives you the second error?
Oh, actually i think i see the problem.
I think it is the use of the dbg
keyword. It doesn't return anything. It just prints a value. So i think that is confusing the compiler. Main is expected to evaluate to a task that can't error (errors need to be handled in main). So you would need to return a final task.
What if you change your attempt lambda to something like:
when res is
Ok {} ->
dbg "Ok"
Task.succeed {}
Err err ->
dbg err
Task.succeed {}
Thanks! I think it worked. I though that main needed to return something but I was not sure what it was
Last updated: Jul 05 2025 at 12:14 UTC