Stream: beginners

Topic: destructuring error?


view this post on Zulip itmuckel (Mar 31 2023 at 09:00):

I got this weird error message I don't understand:

── UNKNOWN OPERATOR ───────────────────────────────────────────────── day2.roc ─

This looks like an operator, but it's not one I recognize!

25│      [a, b] = parseLine line
                ^
parseLine = \line ->
    parts = Str.graphemes line
    a = List.get parts 0 |> unwrap
    b = List.get parts 2 |> unwrap
    [a, b]

getLineScore = \line ->
    [a, b] = parseLine line
    me = when a is
        "A" -> 1
        "B" -> 2
        "C" -> 3
    other = when b is
        "X" -> 1
        "Y" -> 2
        "Z" -> 3

    outcome me other

view this post on Zulip Folkert de Vries (Mar 31 2023 at 09:05):

oh that's fun

view this post on Zulip Folkert de Vries (Mar 31 2023 at 09:05):

the list pattern is parsed as an expression

view this post on Zulip Anton (Mar 31 2023 at 09:05):

I don't think we support list destructuring like that?

view this post on Zulip Folkert de Vries (Mar 31 2023 at 09:05):

you can use an explicit when

view this post on Zulip Folkert de Vries (Mar 31 2023 at 09:05):

yeah the pattern is not exhaustive anyway

view this post on Zulip Folkert de Vries (Mar 31 2023 at 09:05):

but I'd guess that [..] = someList works

view this post on Zulip Folkert de Vries (Mar 31 2023 at 09:06):

which is not useful in any way

view this post on Zulip Anton (Mar 31 2023 at 09:06):

I'll make an issue for a nicer error message

view this post on Zulip itmuckel (Mar 31 2023 at 09:25):

Oh, so I need to do

when (parseLine line) is
    [a, b] -> [a, b]
    _ -> crash "fail"

to get that destructuring? :tear:

view this post on Zulip Anton (Mar 31 2023 at 09:28):

Yes, for roc it's a key point to minimize runtime errors. So for that reason we should not allow an "easy to reach for syntax" that can crash.

view this post on Zulip Anton (Mar 31 2023 at 09:30):

Reliable apps do not come without sacrifices unfortunately, but I suppose AIs will soon be able to generate most of your error-handling code :p

view this post on Zulip itmuckel (Mar 31 2023 at 09:39):

Well, I know it is actually a good thing. :-) In Advent of Code you know it's throwaway code, but in general it is better to force the user to do the right thing, I guess, although rust sometimes drives me mad :-D

view this post on Zulip dank (Mar 31 2023 at 09:39):

Anton said:

Yes, for roc it's a key point to minimize runtime errors. So for that reason we should not allow an "easy to reach for syntax" that can crash.

case in point, in languages like python it's very common to accidently raise ValueError: not enough values to unpack

view this post on Zulip dank (Mar 31 2023 at 09:39):

or too many values to unpack, ofc

view this post on Zulip Nick Hallstrom (Mar 31 2023 at 14:53):

Would this work if you returned a tuple instead of a list? Seems like it should, right? I’m pretty sure this would work with a tag


Last updated: Jul 06 2025 at 12:14 UTC