Stream: beginners

Topic: ✔ backpassing style for non-IO


view this post on Zulip Steven Chen (Dec 12 2023 at 19:12):

Just my 2 cents...personally I don't favor backpassing for non-IO (Task) due to the indentation change. E.g. glancing below, it feels like the last line is the return value (instead of of List Str)

result =
    x <- nums |> List.map
    Num.toStr x

The old fashion way is cleaner keeping the lambda closer to List.map

result =
    nums |> List.map \x -> Num.toStr x

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 19:35):

It definitely can read weird at times. Though works great with Result.try for example

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 19:35):

I probably use it too much personally.

view this post on Zulip Steven Chen (Dec 12 2023 at 19:38):

also we can only do one backpassing block at a time, right? because the lambda body now takes that indentation

view this post on Zulip Steven Chen (Dec 12 2023 at 19:42):

Brendan Hansknecht said:

It definitely can read weird at times. Though works great with Result.try for example

because Result.try is a typical Monad (with my limited Haskell understanding). so it works naturally with the backpassing style (do-notation in Haskell)

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 19:44):

Just trying to point out that it works with more than just io. It works with anything monad like. Random number generation can also be nice for this.

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 19:45):

Yes, one block at a time due to indentation.

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 19:46):

Though you can always do:

task =
        x <- ...
        y <- ...
        ...

# continue on outside of that scope

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 19:46):

So one level of indentation for a whole chain of calls

view this post on Zulip Steven Chen (Dec 12 2023 at 19:47):

gotcha. the callback chains can be one block

view this post on Zulip Notification Bot (Dec 15 2023 at 00:20):

Steven Chen has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC