I have this simple program that I am trying to parse the command line arguments from a basic-cli app, but I cannot please the roc alpha2 compiler. It is complaining that map_try expects 2 arguments, and I'm passing only 1. But the map_try is in a pipeline, I was expecting this to work. Any help?
app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }
import pf.Arg
import pf.Stdout
parse_arg = |arg|
{ after, before } = Str.split_first(arg, ".")?
Ok (Str.to_dec(before)?, Str.to_dec(after)?)
main! : List Arg.Arg => Result {} [Exit I32 Str]
main! = |args|
args
|> List.map(Arg.display)
|> List.map_try(parse_arg) ? |_| Exit 1 "Invalid arg"
|> List.for_each! |(day, sub)| Stdout.line! "Solving problem forday ${Num.to_str day} sub ${Num.to_str sub}" ?? {}
|> Ok
The error message:
The map_try function expects 2 arguments, but it got only 1:
14│ |> List.map_try(parse_arg)
^^^^^^^^^^^^
And version:
$ roc --version
roc nightly pre-release, built from commit 689c58f on Mi 29 Jan 2025 09:02:05 UTC
When I change main! to
main! : List Arg.Arg => Result {} [Exit I32 Str]
main! = |args|
parsed_args : Result (List (Dec, Dec)) _
parsed_args =
args
|> List.map(Arg.display)
|> List.map_try(parse_arg)
Ok({})
It typechecks
So I think it's probably a weird interaction between whitespace function calls and parens function calls?
The new ?
binop operator may be confused around this
@Ian Liu Rodrigues for now, you can replace
|> List.map_try(parse_arg) ? |_| Exit 1 "Invalid arg"
with
|> List.map_try(parse_arg)
|> Result.map_err(|_| Exit(1, "Invalid arg"))?
Sweet, thanks!
Ian Liu Rodrigues has marked this topic as resolved.
Should the original code work @Sam Mohr? If so, I'll make an issue for it
It should yes
Not super worried, depending on how long WSA stays around
We should make an issue regardless
Last updated: Jul 06 2025 at 12:14 UTC