Question on pattern matching; trying to use tagged parameter, but I must be messing up the formatting. I have this, and it works:
when elem is
UnknownStrategy _ -> state
RockVsRockDraw score -> state + score
RockVsPaperWin score -> state + score
RockVsScissorsLoss score -> state + score
PaperVsRockLoss score -> state + score
PaperVsPaperDraw score -> state + score
PaperVsScissorsWin score -> state + score
ScissorsVsRockWin score -> state + score
ScissorsVsPaperLoss score -> state + score
ScissorsVsScissorsDraw score -> state + score
But I wanna write this:
when elem is
UnknownStrategy _ -> state
_ score -> state + score
But she gets mad about formatting; I've verified indentation.
── MISSING ARROW ──────────────────────────────────────────────────── main.roc ─
I am partway through parsing a when expression, but got stuck here:
65│ when elem is
66│ UnknownStrategy _ -> state
67│ _ score -> state + score
^
I was expecting to see an arrow next.
Note: Sometimes I get confused by indentation, so try to make your when
look something like this:
when List.first plants is
Ok n ->
n
Err _ ->
200
Notice the indentation. All patterns are aligned, and each branch is
indented a bit more than the corresponding pattern. That is important!%
I don't think we support pattern matching like that: _ score
Ah, maybe holes only support... like 1 hole? I'm coming from ReScript where you just litter those things everywhere, my bad. So is _ like a catch all and not a hole?
yes
If so, that makes sense, ok, thanks!
Last updated: Jul 06 2025 at 12:14 UTC