Why do i get Too many args error when is use Stdout.line this way
Stdout.line "Hello, world"
Stdout.line "Hello, Again"
A message was moved here from #beginners > Formatting a closure in a record by Luke Boswell.
Hey @victor dumbiri , it may help to think of it like this
main =
Stdout.line "Hello, World" |> Task.await \{} ->
Stdout.line "Hello Again"
If you look at the type that main
is expecting, it requires a Task {} *
I think, and the type of Stdout.line is Task {} *
, but when you want to chain these in sequence you need to use another function to combine them
My example shows how you can do this using Task.await
That is also the same as this, which uses backpassing syntax <-
which de-sugars into the above example
main =
{} <- Stdout.line "Hello, World" |> Task.await
Stdout.line "Hello Again"
@Luke Boswell okay, thanks
Just to add some extra context, with the original code, roc essentially is seeing it as:
Stdout.line "Hello, world" Stdout.line "Hello, Again"
Where the first Stdout.line
is getting passed 3 args the string "Hello, world"
, the function Stdout.line
and the string "Hello, Again"
.
This is probably a place where we should invest in better error messages.
I made #5602 for this
Last updated: Jul 06 2025 at 12:14 UTC