Stream: beginners

Topic: Do expressions


view this post on Zulip misterdrgn (Dec 31 2024 at 15:15):

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.

view this post on Zulip Anton (Dec 31 2024 at 15:29):

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 :)

view this post on Zulip Anton (Dec 31 2024 at 15:29):

I'll see if I can make an example of your nested calls

view this post on Zulip misterdrgn (Dec 31 2024 at 15:43):

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.

view this post on Zulip Anton (Dec 31 2024 at 15:46):

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

view this post on Zulip misterdrgn (Dec 31 2024 at 15:52):

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.

view this post on Zulip Anton (Dec 31 2024 at 15:52):

Correct :)

view this post on Zulip Anton (Dec 31 2024 at 15:58):

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!

view this post on Zulip misterdrgn (Dec 31 2024 at 16:09):

Yeah, understood, thanks.


Last updated: Jul 05 2025 at 12:14 UTC