Stream: beginners

Topic: ✔ Help! Why does this not parse?


view this post on Zulip Michał Łępicki (Oct 16 2022 at 14:06):

main : Program
main = Program.noArgs (Task.attempt mainTask \result ->
    exitCode = when result is
        Ok {} -> 0
        Err _ -> 1
    Task.succeed {} |> Program.exit exitCode
    )

mainTask =
    Task.await
        (File.readUtf8 (Path.fromStr "../../1"))
        \contents ->
            x = if contents == "asdf" then 1 else 2

            Num.toStr x
            |> Stdout.line

I'm getting this error, but {} is a pattern, no?

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

9│          Ok {} -> 0
              ^

I was expecting to see a pattern next

view this post on Zulip Brendan Hansknecht (Oct 16 2022 at 14:33):

I think the issue is tabbing. I am not exactly sure how this part of the parser works, what happens if you write:

exitCode =
    when result is
        Ok {} -> 0
        Err _ -> 1

view this post on Zulip Michał Łępicki (Oct 16 2022 at 14:33):

It works! Thank you!

view this post on Zulip Notification Bot (Oct 16 2022 at 14:33):

Michał Łępicki has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC