I launch the feedback for Day 1 of AoC! (my solution)
Program.quick
, it of course necessitate more boilerplate for task failures handling (or I didn't found how to do it simpler). But I think that is for the sake of a better understanding.ln -s
/cp
of cli-platform
:tada: imports
. For example, I can use pf.Task
as a "builtin" but not as the type definition. And the pf.Task.{ Task }
works for both which seem weird to me.Not sure If this is a good way for handling task failures but I just did |> Task.onFail (\_ -> Task.succeed {})
. It was my first actual roc programm today!
Friendship ended with Result.withDefault
, now crash
is my best friend: my solution.
list pattern matching :heart_eyes:
hey y'all! excited to Roc with everybody!!!
I have a silly question -- how do you parse a file :sweat_smile: ? I currently just pasted the input into my main.roc file
Shritesh Bhattarai said:
Friendship ended with
Result.withDefault
, nowcrash
is my best friend: my solution.
oooh I'm stealing this parsing logic, thanks @Shritesh Bhattarai
There are some more examples of using the CLI platform to work with files in this example: https://github.com/roc-lang/roc/blob/2a27d3c05f7974adf87e782704eab8d43c80652e/examples/cli/file.roc
I always did it manual with string splitting and such. Some people use proper parser combinators.
You can find some examples from last years problems here if you need some code to look at for parsing this way: https://github.com/bhansconnect/roc-aoc-2021
Note: may not compile anymore without some minor updates and tweaks due to changes to roc and the cli platform.
here's my solution
I've playing around with parsers and wanted to practice, so my answer is probably overkill for this first one. I should eventually be able to simplify these parsers a lot as my understanding grows I think. My plan is to have a base that should scale a bit nicer into the later AoC challenges. :grinning_face_with_smiling_eyes:
Srinivas Rao-Mouw said:
Shritesh Bhattarai said:
Friendship ended with
Result.withDefault
, nowcrash
is my best friend: my solution.oooh I'm stealing this parsing logic, thanks Shritesh Bhattarai
Interestingly, this does not run for me on macOS M1. I was also attempting Day 1 using Roc but I might not be on the ideal platform for such tinkering ..
(using a main.roc
with the linked code)
❯ roc
The program crashed with:
Failed to read and parse input
Here is the call stack that led to the crash:
roc.panic
app.(anonymous function)
Task.(anonymous function)
rust.main
Can I adjust Task.onFail
to provide the reason for the crash?
I'm excited to have muddled through the first one with good help from friendly folks here
EDIT: Ha, ah, that was just part 1
A little late to the party, but here's my day 1
I also finally got day 1 completed, here's another solution
Also catching up! My solution (first roc program!)
Thanks to everyone else sharing! Getting some good ideas for how to improve
Day 01 – my first Roc program, so happy I could figure it out...! :innocent:
Setting up the 'boilerplate' code to make the tasks work (like trying to understand that main has the type of 'Task') was the most difficult part for me.
Last updated: Jul 06 2025 at 12:14 UTC