Stream: beginners

Topic: ✔ Help with basic parsing


view this post on Zulip Piotr Brzeziński (Apr 02 2024 at 17:30):

Hi everyone! I just started playing with Roc and I've ran into a wall trying to parse some cli args. My code is super simple:

app "hello"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br" }
    imports [pf.Stdout, pf.Arg, pf.Task]
    provides [main] to pf

main =
    args <- Arg.list |> Task.await

    parsedArgs = Arg.parse argsParser args

    dbg parsedArgs

    Stdout.write "hi"

argsParser =
    Arg.succeed (\name -> \amount -> { name, amount })
    |> Arg.withParser (Arg.i64Option { long: "amount" })
    |> Arg.withParser (Arg.strOption { long: "name" })
    |> Arg.program { name: "test", help: "hey there" }

and then when I try to run it, I get

thread 'main' panicked at 'Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x13\x00\x00\x00\x1b\x00\x00\x00c\x05=\x1a\x179\x00F"), definition of value binding ValueId(60): could not find func in module ModName("UserApp") with name FuncName("\x13\x00\x00\x00\x8c\x00\x00\x005K\xf7:8\xfd~\xf7")', crates/compiler/gen_llvm/src/llvm/build.rs:5759:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace```

and I'm a bit confused as where I made the mistake. I guess it could be how I use `Arg.program` (name param?) because I wasn't sure looking at the docs what the name should be.

Any help appreciated!

view this post on Zulip Anton (Apr 02 2024 at 17:51):

Hi @Piotr Brzeziński,
This is a known issue, this similar example does work. But I'm not sure what the bug-causing difference between them is.

view this post on Zulip Piotr Brzeziński (Apr 02 2024 at 18:07):

Hey Anton!

Fair enough, thanks for letting me know. I'll go with manual parsing for now then :).

view this post on Zulip Karakatiza (Apr 03 2024 at 18:49):

Unfortunately the nice Arg.withParser API's source code compilation is broken for an undefined time, so only manual parsing of Arg.list result is possible for now

view this post on Zulip Notification Bot (Apr 08 2024 at 12:33):

Piotr Brzeziński has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC