Very minor AoC day 4 part 1 spoiler
The roc compiler gives me a syntax error , and tells me that "This pattern is malformed", and points at the two Bool.true
things.
What am I doing wrong?
Maybe related, but I originally tried making the third pattern (_, Bool.false)
, but if I do that, Roc tells me that I'm missing the pattern (_, _)
. That seems weird? Surely the only possible values of Bool
is Bool.true
and Bool.false
?
Maybe I'm just not allowed to pattern match on bools in general? Is that a design decision? I guess I could nest some if
expressions instead?
Anyway, help and advice is much appreciated here. I really feel like there's something about Bools that I'm not understanding fully.
Asbjørn Olling said:
Maybe related, but I originally tried making the third pattern
(_, Bool.false)
, but if I do that, Roc tells me that I'm missing the pattern(_, _)
. That seems weird? Surely the only possible values ofBool
isBool.true
andBool.false
?
I think this is a known issue.
Coolcool. Good to know. That at least explains why I could have (_, Bool.false)
in my third pattern.
I'm still confused by why the first two patterns give a syntax error, though?
I'll take a look
Maybe I'm just not allowed to pattern match on bools in general?
I indeed think this is the case. I'll check if we've discussed this before...
We've had several lengthy discussions about it, we're considering a solution now.
I would recommend going with an if
for now
I aleady did ;)
Worked around it with an if, and that seems to work fine.
cardPoints : Card -> Nat
cardPoints = \card ->
List.walk card.myNums 0 \points, myNum ->
isWin = List.contains card.winNums myNum
if isWin && points == 0 then
1
else if isWin then
points * 2
else
points
and now I understand that I wasn't misunderstanding pattern match syntax - it's just bools that are a bit funky for now.
it still feels a bit weird to me that bools aren't just tags like everything else (even Result is). It seems like if I just mapped Bool.true
and Bool.false
to tags True
and False
, all the pattern matching stuff would work.
I assume there's a good reason for it, that I just don't undestand yet - given that the tags approach would be the most obvious (right?)
Something performance related maybe?
Oh I found the good stuff.
https://docs.google.com/document/d/1a51n7eIEbPjCWnGaL-pWbZBsRfi55GVQwIdPQTUu49Q/edit#heading=h.kikaz4s9uvzo
I'll go get smart now
Thanks for the help, @Anton !
Last updated: Jul 06 2025 at 12:14 UTC