Stream: beginners

Topic: Pattern matching on records


view this post on Zulip jan kili (Sep 19 2022 at 00:41):

How does pattern matching on records work? I'm doing this

when Decode.fromBytes myJson Json.fromUtf8 is
    Ok { message: { content } } -> process content
    _ -> process "uh oh no content"

and I'm getting

── UNFINISHED WHEN ────────────────────────────────────────────────── main.roc ─

I was partway through parsing a when expression, but I got stuck here:

31│          Ok { message: { content } } ->
               ^

I was expecting to see a pattern next

Note: Here is an example of a valid when expression for reference.

    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!

view this post on Zulip Richard Feldman (Sep 19 2022 at 13:58):

that looks like a parsing bug - can you open an issue for it?

view this post on Zulip J.Teeuwissen (Sep 19 2022 at 14:04):

@JanCVanB Can you show the context of the when...is? I remember having similar complaints when the when...is did not have a separate line after the function -> (presumably bad indentation).


Last updated: Jul 06 2025 at 12:14 UTC