I anyone else seeing TOO FEW ARGS reports when using pipes on main:HEAD(latest latest)?
I have to imagine we have CI tests that run Builtins or some other tests for stuff like that...
Let's see...
I'm on:
❯ roc --version
roc built from commit f3376af9c1, committed at 2025-01-17 15:29:09 UTC
Any pipes and I get TOO FEW ARGS
» x = |y| y + 123
<function> : Num a -> Num a
»
Enter an expression to evaluate, or a definition (like x = 1) to use later.
- ctrl-v + ctrl-j makes a newline
- :q quits
- :help shows this text again
» 123 |> x
246 : Num *
»
I think it's only multiline pipes
The repl is busted as well
Can someone with perms move this to a thread in #bugs ?
9 messages were moved here from #ideas > ?
for mapping Result Err values by Luke Boswell.
Thanks Luke!
Can you share some reproductions @Anthony Bullard
Sure
Well...Maybe not...
Now I'm pissed off.
@Anton Can't reproduce now because why would good things happen, but the REPL still does not allow you to create multiline expressions with ctrl-j
or ctrl-v
@Anton Got it
module [run!]
import pf.Stdout
import pf.Path exposing [Path]
raw_exercises! : Path => List Path
raw_exercises! = |path|
Path.list_dir!(path)
?? []
exercise_numbers : List Path -> List U32
exercise_numbers = |paths|
paths
|> List.keep_if(|p| Str.starts_with(Path.display(p), "exercise_") && Str.ends_with(Path.display(p), ".roc"))
|> List.keep_oks(
|p|
p_str = Path.display(p)
p_parts = Str.split_on(p_str, "_")
when p_parts is
[_, number, ..] -> Ok(Str.to_u32(number)?)
_ -> Err(InvalidEx),
)
run! : Path => Result {} _
run! = |path|
ex = raw_exercises!(path) |> exercise_numbers |> List.sort_asc()
num = [] |> List.first()?
Stdout.line!("Checking your solutions for exercise ${Num.to_str(num)}...")
The minimal repro would be
module [something!]
import pf.Stdout
something! = |_|
ex = ["hello"] |> List.first()?
Stdout.line!(ex)
So pipe + PNC + try suffix?
I made #7530 for this.
If we look at the desugared version we'll probably be able to make sense of this.
@Sam Mohr may also have an idea what's going on
The desugaring should be working, but a well placed dbg! might be useful
I'm going to look at this issue
Screenshot from 2025-01-20 15-53-17.png
This is the code after desugaring. It's obvious what is going wrong but I'm not sure how things should be changed :thinking:
Desugar to a Defs then break up the pipe and pass the new def explicitly?
@Sam Mohr, can you weigh in as well here?
He'll probably wake up in 3 hours :tears:
Anthony is on the money IMO
We shouldn't worry about performance since we are removing pizza from the menu
Once it's gone, we can figure out how to make this work better
Desugar to a Defs then break up the pipe and pass the new def explicitly?
Should I do this for every use of the pizza operator (here in the code)?
That makes sense to me. Easier to reason about
Just to note, this is incorrect code, even if the error message is misleading:
module [something]
something = |_|
["hello"] |> List.first()?
The ? means we're trying to return Str
as the final expression instead of Result Str _
Hopefully, my attempt to fix things will alleviate that anyway
Fixed in https://github.com/roc-lang/roc/pull/7548
module [something]
something = |_|
["hello"] |> List.first()?
> cargo run --bin roc -- check test2.roc
...
── TYPE MISMATCH in ../test2.roc ───────────────────────────────────────────────
This returns something that's incompatible with the return type of the
enclosing function:
4│ ["hello"] |> List.first()?
^^^^^^^^^^^^^^^^^^^^^^^^^
This returns an Err of type:
[Err [ListWasEmpty]]
But I expected the function to have return type:
Str
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 121 ms.
incompatible with the return type of the enclosing function
I don't understand, the type of something
is not specified, so how does it know the return type should be a Str
?
Because it's operating on a List Str
And the ? can AST node has special Result type checking I added
We could make the error message better when ? is used on the return value of a function, I don't think that's ever valid
But this message is accurate for now
So I don't think we should block release on such an error message
Assuming we merge this PR
In this case the ?
is not used on the return value:
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP>
}
import pf.Stdout
main! = |_args|
Stdout.line!("")
find : List U64, U64 -> Result U64 [ValueWasNotFound (List U64) U64]
find = |array, value|
binary_search = |min_index, max_index|
middle_index = (min_index + max_index) // 2
middle_value = array |> List.get(middle_index)?
if middle_value == value then
Ok(middle_index)
else if min_index == max_index then
Err(ValueWasNotFound(array, value))
else if middle_value < value then
Ok(binary_search((middle_index + 1), max_index)?)
else
Ok(binary_search(min_index, (middle_index - 1))?)
binary_search(0, List.len(array))
|> Result.on_err(|_| Err(ValueWasNotFound(array, value)))
# finds a value in an array with one element
expect
result = [6] |> find(6)
result == Ok(0)
What's the problem here, is it just operator precedence?
I approved the PR
The error is:
── TOO FEW ARGS in BinarySearch.roc ────────────────────────────────────────────
The get function expects 2 arguments, but it got only 1:
7│ middle_value = array |> List.get(middle_index)?
^^^^^^^^
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 30 ms
Yes, precendence would be the issue
a suffix would bind stronger than a infix
Hmm, in the case of
4│ ["hello"] |> List.first()?
^^^^^^^^^^^^^^^^^^^^^^^^^
It looks like |>
is binding stronger
Anton said:
The error is:
── TOO FEW ARGS in BinarySearch.roc ──────────────────────────────────────────── The get function expects 2 arguments, but it got only 1: 7│ middle_value = array |> List.get(middle_index)? ^^^^^^^^ Roc does not allow functions to be partially applied. Use a closure to make partial application explicit. ──────────────────────────────────────────────────────────────────────────────── 1 error and 0 warnings found in 30 ms
Is this on my PR branch?
No
Okay good
The precedence is changed in PR#7548, it seems like the old precedence made more sense
Merged
You're right that the old precedence made more sense
The problem IMO is that pizza and PNC don't make sense together
But we need to support them both somehow while they coexist in this middle Roc
So this PR is the only way for a pipeline to make sense IMO
Do we have an issue for this?
https://github.com/roc-lang/roc/issues/7530
Already closed since my PR should have fixed it
Ah, great, thanks Sam. I must need to update.
Nightly release is very behind right now, you'll need to come from source for that to be available
Last updated: Jul 06 2025 at 12:14 UTC