It dumps the entire signatures on screen, despite the error being much simpler. And the solution is just as simple as the error: adding a ! after the function name (in case of functions that have both effectful and pure variants).
app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.22.0/F1JVZPYfWP71s8vk6tHcV1Qx1Ef6CZkwswGoCn8VHZmL.tar.zst" }
import pf.Stdout
main! = |_| {
strings = ["a", "b", "c"]
_print_results = strings.map_try( # Add a ! here and the error is gone.
|str| Stdout.line!(str),
)
Ok({})
}
Output of roc check
── ✗ type mismatch ──────────────────────── src/bug.roc:8:19
The map_try method on List has an incompatible type.
_print_results = strings.map_try(
^^^^^^^
The method map_try has the type:
List(a), (a -> Try(b, err)) -> Try(List(b), err)
where [a.from_quote : Str -> Try(a, [BadQuotedBytes(Str)])]
But I need it to have the type:
List(a), (Str => Try({}, [StdoutErr(IOErr), ..])) -> _ret
where [a.from_quote : Str -> Try(a, [BadQuotedBytes(Str)])]
── 1 error and 0 warnings ────────────────── src/bug.roc
Suggested user-friendly error message:
The first argument of `List.map_try()` expects a pure function. Got an effectful one.
It easily fits in the text editor as an LSP diagnostic, even if it only displays one line and truncates the rest of the message.
Also, if the function has an effectful variant (same name, just with a ! at the end), suggest it:
The first argument of `List.map_try()` expects a pure function. Got an effectful one.
Maybe you meant to use `List.map_try!()` instead?
I recommend showing this effectful vs pure error even if the argument types or the arity is mismatching, since this is the most important thing to correct first, then fix the arity, then the types. The current error shows everything at once (the signatures show the arity, the types, the effects), but it's harder to debug. If a fix is implemented together with #11032, the user gets a much better DX: first they fix the effectfulness (this issue), then they get an arity mismatch error (#11032), then after they fix that, they get a type mismatch error, which is much easier to understand, since the arity and effects are fixed already. It's much easier to diagnose and fix these one by one than all at once. Especially as a beginner.
It dumps the entire signatures on screen, despite the error being much simpler. And the solution is just as simple as the error: adding a
!after the function name (in case of functions that have both effectful and pure variants).Output of
roc checkSuggested user-friendly error message:
It easily fits in the text editor as an LSP diagnostic, even if it only displays one line and truncates the rest of the message.
Also, if the function has an effectful variant (same name, just with a
!at the end), suggest it:I recommend showing this effectful vs pure error even if the argument types or the arity is mismatching, since this is the most important thing to correct first, then fix the arity, then the types. The current error shows everything at once (the signatures show the arity, the types, the effects), but it's harder to debug. If a fix is implemented together with #11032, the user gets a much better DX: first they fix the effectfulness (this issue), then they get an arity mismatch error (#11032), then after they fix that, they get a type mismatch error, which is much easier to understand, since the arity and effects are fixed already. It's much easier to diagnose and fix these one by one than all at once. Especially as a beginner.