This error is pretty bad. Very hard to realize what is wrong. Took me a while before I noticed the difference:
The argument is an anonymous function of type:
{ … }, Str => { … }
But walk needs its 3rd argument to be:
{ … }, Str -> { … }
We should make this message clearer somehow
Explicitly state the function is effectful but the caller requires the function to be pure.
Sounds like we need two changes
@Brendan Hansknecht do you have the full code? I'm happy to reduce to a repro
roc check
on this:
app [main!] { pf: platform "../platform/main.roc" }
import pf.Stdout
import pf.File
dir_list : List Str
main! = \_args ->
foo = List.walk dir_list { file: [], dir: [] } \state, elem ->
when File.is_file! elem is
Ok is_file if is_file ->
{ state & file: List.append state.file elem }
Ok _ ->
{ state & dir: List.append state.dir elem }
_ ->
# Just ignore failures
state
Stdout.line! "Hello, World!"
will see:
This 3rd argument to walk has an unexpected type:
9│> foo = List.walk dir_list { file: [], dir: [] } \state, elem ->
10│> when File.is_file! elem is
11│> Ok is_file if is_file ->
12│> { state & file: List.append state.file elem }
13│>
14│> Ok _ ->
15│> { state & dir: List.append state.dir elem }
16│>
17│> _ ->
18│> # Just ignore failures
19│> state
The argument is an anonymous function of type:
{ … }, Str => { … }
But walk needs its 3rd argument to be:
{ … }, Str -> { … }
Thanks!
Pretty simple:
module [broken, effectful!]
effectful! : Str => Result Str []
broken = List.map [] effectful!
Produces
── TYPE MISMATCH in test.roc ───────────────────────────────────────────────────
This 2nd argument to map has an unexpected type:
5│ broken = List.map [] effectful!
^^^^^^^^^^
This effectful! value is a:
Str => Result Str []
But map needs its 2nd argument to be:
Str -> Result Str []
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 30 ms.
https://github.com/roc-lang/roc/issues/7426
Last updated: Jul 05 2025 at 12:14 UTC