Is a function that maps a Result to a Task in cli-platform
? I would imagine there would be one that maps Ok
to Task.succeed
and Err
to Task.fail
.
I am pretty sure the answer is currently no, but it probably should be sdded
Something like:
fromResult = \result ->
when result is
Ok x -> Task.succeed x
Err e -> Task.fail e
sounds reasonable! If anyone would like to make a PR to add it, here's the file where it would go:
https://github.com/roc-lang/roc/blob/main/examples/interactive/cli-platform/Task.roc
@Richard Feldman would it be better to put it in https://github.com/roc-lang/roc/blob/main/examples/interactive/cli-platform/InternalTask.roc? Since fromEffect
also sits there...
The tutorial says Tasks have two type params (Task {} *
), but the definitions in Task.roc
all have three - Task ok err fx
. What is this fx?
No, fromEffect is an internal function that users shouldn't directly access. Roc has managed effects so they are treated very specially.
This new fromResult function is very different. It has nothing to do with effects and there is no reason to make it internal.
Regarding fx
, the docs should be updated to include this.
Each different effect in the platform has its own tag that goes in this part of the type.
So the type system is able to keep track of which effects are used in which parts of the app code. This is useful information for the app developer. If some effect goes wrong, you can find the problem easily.
@Richard Feldman, I can take that on. The only documentation one adds to the platform is the comment above the function definition? Are there other places to add documention for a platform's API?
you're correct - that's the only place!
Here's the PR:
https://github.com/roc-lang/roc/pull/4265
Chris Duncan has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC