Does/will Roc support anything like haskell’s do or gleam’s use or ocaml’s let*, for example for nested calls to map? Or is there a different idiomatic approach for handling this in Roc? Thanks.
We used to have this, it was called backpassing. But it was removed because it was one of the most complicated things to understand in Roc. I have not missed it so far :)
I'll see if I can make an example of your nested calls
Thanks. Another example would be Result.try, if you want to try several operations in a row, where each depends on the previous one succeeding.
For that we have a try keyword, as well as a ?
operator. I think we only plan on keeping one of those in the long term
Oh right! Apologies, that’s what I get for asking when I haven’t looked at the tutorial in a while. So there’s syntax for Result and I believe for Task, but there isn’t generalized syntax for apply the same idea to lists, sets, etc.
Correct :)
The nested map calls would just be this, nothing special:
app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.18.0/0APbwVN1_p1mJ96tXjaoiUCr8NBGamr8G8Ac_DrXR-o.tar.br" }
import pf.Stdout
main! = \_args ->
List.map [1, 2] (\x ->
List.map [10, 20] (\y ->
List.map [100, 200] (\z ->
x + y + z
)
)
)
|> Inspect.toStr
|> Stdout.line!
Yeah, understood, thanks.
Last updated: Jul 05 2025 at 12:14 UTC