In this example:
main =
Task.attempt processTask \p ->
when p is
Ok s -> Stdout.line s
Err ReadErr -> Stdout.line "Tried to read"
Err WriteErr -> Stdout.line "Tried to write"
|> Program.quick
processTask : Task.Task Str [ReadErr, WriteErr] []
Compiler output says:
This 2nd argument to attempt has an unexpected type:
...
The argument is an anonymous function of type:
[Err [ReadErr, WriteErr], Ok Str] ->
Task {} * [Write [Stdout]*]* ?
But attempt needs its 2nd argument to be:
Result Str [ReadErr, WriteErr] -> Task {} * [] ?
Let's say processTask
doesn't produce any event, why the compiler tells me to handle others by putting []*
?
This is due to a quirk of how type checking in Roc works. We're working on making it better! But for now, in this case, []
means it can be used in only a place where a []
is expected, and nothing more than a []
. So you add []*
to say "you can use this as a []
, or any tag that has more variants than []
"
Ok, thank you!
Last updated: Jul 06 2025 at 12:14 UTC