Stream: roctoberfest

Topic: Day 2


view this post on Zulip Ghislain (Oct 01 2022 at 22:56):

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".

view this post on Zulip jan kili (Oct 01 2022 at 23:41):

I've definitely been tripped up by that before!

view this post on Zulip Brendan Hansknecht (Oct 01 2022 at 23:55):

Yeah, i always parenthize lambdas unless I am using backpacking or they are on their own indented scope with new lines

view this post on Zulip Brendan Hansknecht (Oct 02 2022 at 06:42):

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.

view this post on Zulip Brendan Hansknecht (Oct 02 2022 at 06:44):

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.

view this post on Zulip Brendan Hansknecht (Oct 02 2022 at 15:15):

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.

view this post on Zulip Ayaz Hafiz (Oct 02 2022 at 15:23):

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

view this post on Zulip Brian Carroll (Oct 02 2022 at 15:27):

We have a parser lib in the examples directory, could be a starting point.

view this post on Zulip Folkert de Vries (Oct 02 2022 at 15:29):

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

view this post on Zulip Ayaz Hafiz (Oct 02 2022 at 15:36):

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!

view this post on Zulip Brian Carroll (Oct 02 2022 at 16:20):

:laughing: Well I suppose it was inevitable that bunch of people interested in new languages would build a load of parsers!

view this post on Zulip Ayaz Hafiz (Oct 02 2022 at 23:09):

@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:

view this post on Zulip Ayaz Hafiz (Oct 02 2022 at 23:10):

Ideally (\_ -> (\n -> Forward n)) could be reduced to (\_ -> Forward) but that doesn't check today: https://github.com/roc-lang/roc/issues/4150

view this post on Zulip Luke Boswell (Oct 06 2022 at 08:55):

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

view this post on Zulip Anton (Oct 06 2022 at 10:31):

I'll take a look

view this post on Zulip Anton (Oct 06 2022 at 10:53):

@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.

view this post on Zulip Luke Boswell (Oct 06 2022 at 10:56):

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:

view this post on Zulip Luke Boswell (Oct 06 2022 at 11:05):

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?

view this post on Zulip Anton (Oct 06 2022 at 11:40):

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 :)

view this post on Zulip Richard Feldman (Oct 06 2022 at 14:09):

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:

view this post on Zulip Richard Feldman (Oct 06 2022 at 14:09):

we know those are still lurking in the code base, but we don't know where they all are

view this post on Zulip Brendan Hansknecht (Oct 06 2022 at 15:08):

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.

view this post on Zulip Anton (Oct 06 2022 at 16:37):

roc filename.roc has been changed some time ago to do the same thing as roc dev filename.roc

view this post on Zulip Anton (Oct 06 2022 at 16:37):

See https://github.com/roc-lang/roc/blob/main/crates/cli/src/main.rs

view this post on Zulip Brendan Hansknecht (Oct 06 2022 at 16:49):

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.

view this post on Zulip Richard Feldman (Oct 06 2022 at 16:52):

it's going to become different though, specifically with regards to expect - so roc dev is the one to use now!

view this post on Zulip Richard Feldman (Oct 06 2022 at 16:52):

the other one is strictly for running hashbang scripts now (since those can't necessarily pass subcommands to roc)

view this post on Zulip Richard Feldman (Oct 09 2022 at 02:33):

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!

view this post on Zulip Michał Łępicki (Oct 17 2022 at 17:02):

Day 2 done! I filed two more Roc issues while working on it :sweat_smile:

view this post on Zulip Ayaz Hafiz (Oct 17 2022 at 17:05):

Congrats!! And thanks for the issues :) they help us see what really needs fixing!

view this post on Zulip Notification Bot (Oct 17 2022 at 17:05):

Ayaz Hafiz has marked this topic as resolved.

view this post on Zulip Notification Bot (Oct 17 2022 at 17:05):

Ayaz Hafiz has marked this topic as unresolved.

view this post on Zulip Ayaz Hafiz (Oct 17 2022 at 17:06):

(oops, accidentally clicked resolve)


Last updated: Jul 06 2025 at 12:14 UTC