For day-2, I've been a bit stuck to find the idiomatic way to extract the 2 values from the string. Looking forward to see your findings.
And I fought again against the compiler with a miss interpretation of |>
in this example:
lines
|> List.map \line -> Str.split line " " # here the compiler will think the next line belongs to the anonymous function, I have to add parentheses
|> List.walk ...
Intuitively I would like the compiler to understand the indentation which goes back to the first "scope".
I've definitely been tripped up by that before!
Yeah, i always parenthize lambdas unless I am using backpacking or they are on their own indented scope with new lines
Just created my day 2: https://github.com/bhansconnect/roc-aoc-2021/tree/trunk/day2
I think that results and List.map and such or nested when statements is less clean than I would like, but the solution turned out fine.
I like how the Day 2 parser turned out.
I like your use of Str.splitFirst, it definitely helps make it cleaner/more direct than just using Str.split like I did.
As people do day two and mess with parsing, I am really interesting in ways to deal with the parsing, while using pipelining, and avoid explicit branches as much as possible. I feel like I tend to get into chases with nested Results that make that hard. Make the pipeline a lot less pretty.
I want to write a small parser combinator library as I do the 2021 exercises, so that there is something easier to use for the AoC in december
We have a parser lib in the examples directory, could be a starting point.
I'd suggest using the elm parser library as a template https://github.com/elm/parser/tree/1.1.0 it's a pretty efficient way to do things and has at least some built-in support for adding context/error messages
I think parsers may be our largest class of examples. We have the CSV parser, a Base64 parser, JSON parsing, and CLI arg parsing so far!
:laughing: Well I suppose it was inevitable that bunch of people interested in new languages would build a load of parsers!
@Qqwy / Marten thanks for such a sweet parser base from the CSV example. Wrote this parser for the day 2 input: https://gist.github.com/ayazhafiz/35449afcaf3c2b06f577ab9ff3806c16
Feels like parsec again :heart_eyes:
Ideally (\_ -> (\n -> Forward n))
could be reduced to (\_ -> Forward)
but that doesn't check today: https://github.com/roc-lang/roc/issues/4150
I'm getting a strange error on my Day 2 code. I would appreciate any assistance figuring out what I am doing wrong. Day 2 Error
I'll take a look
@Luke Boswell List.keepOks
is expecting to take a function that returns a Result
but your function is returning [Dn U64, Fd (Int Unsigned64), Up U64]a
.
It's best to run the command roc you_folder/main.roc
so you can see build errors, I believe you've been using roc run your_folder/main.roc
. roc run
will try to run the program even if there are build errors.
Thank you @Anton for your help. I'll skip the roc run in future. I just figured it out and uploaded/updated my solution. I was staring at it a while before I could see that. :grimacing:
I feel like I am separating out my functions and adding unit tests for them to check my assumptions and find where the error is. I imagine as I get more familiar and confident with the syntax that wont be necessary.
Sometimes the errors are really hard to decipher and not the pretty printed ones, which are always very helpful. Do you know if the goals is/or it will be possible for Roc or the platforms mature to a point where it is unlikely to get an error that isn't pretty formatted?
I think every build error that is not pretty printed is a compiler bug. So yeah all build errors should definitely end up pretty printed :)
yeah any time you hit one of those, it would be great if you could share it! That way we can prioritize looking into it. :big_smile:
we know those are still lurking in the code base, but we don't know where they all are
Antoher note: roc dev
is probably the best thing here. It first runs roc check
and then roc run
. roc check
tends to print out better errors in cases that the compiler might crash or hit bugs.
roc filename.roc
has been changed some time ago to do the same thing as roc dev filename.roc
See https://github.com/roc-lang/roc/blob/main/crates/cli/src/main.rs
oh, missed that. I thought that roc ...
was essentially build and run if no error. I thought roc dev ...
was check, build, and run if no error.
it's going to become different though, specifically with regards to expect
- so roc dev
is the one to use now!
the other one is strictly for running hashbang scripts now (since those can't necessarily pass subcommands to roc
)
Ghislain said:
For day-2, I've been a bit stuck to find the idiomatic way to extract the 2 values from the string. Looking forward to see your findings.
And I fought again against the compiler with a miss interpretation of|>
in this example:lines |> List.map \line -> Str.split line " " # here the compiler will think the next line belongs to the anonymous function, I have to add parentheses |> List.walk ...
Intuitively I would like the compiler to understand the indentation which goes back to the first "scope".
it now does as of https://github.com/roc-lang/roc/issues/4139 being fixed (thanks @Joshua Warner!) so this should Just Work on the next nightly!
Day 2 done! I filed two more Roc issues while working on it :sweat_smile:
Congrats!! And thanks for the issues :) they help us see what really needs fixing!
Ayaz Hafiz has marked this topic as resolved.
Ayaz Hafiz has marked this topic as unresolved.
(oops, accidentally clicked resolve)
Last updated: Jul 06 2025 at 12:14 UTC