Stream: ideas

Topic: Trailing bang inside of when, if, match branches


view this post on Zulip Kiryl Dziamura (Jul 02 2024 at 09:43):

Does it make sense to allow if, when, match expressions to be treated as statements if there's trailing top-level bang in each branch? For example:

Allow (should it be allowed that a and b can return different Task<a> and Task<b>?)

f = \x, a, b ->
    if x then
        a!
    else
        b! x

    Task.ok x

Error: the return value is not used

f = \x, a, b ->
    if x then
        a
    else
        b x

    Task.ok x

Currently, it can be done with parentheses:

f = \x, a, b ->
    (
        if x then
            a
        else
            b x
    )!

    Task.ok x

view this post on Zulip Kiryl Dziamura (Jul 02 2024 at 11:11):

The same for pizza operator:

Allow

f = \x, g, h ->
    x |> g |> h!

    Task.ok x

Error: the return value is not used

f = \x, g, h ->
    x |> g |> h

    Task.ok x

Currently, it can be done with parentheses:

f = \x, g, h ->
    (
        x |> g |> h
    )!

    Task.ok x

view this post on Zulip Luke Boswell (Jul 02 2024 at 11:53):

Allow (should it be allowed that a and b can return different Task<a> and Task<b>?)

The Chaining Syntax Design Proposal talks about this. In summary I don't this this should be allowed.

This proposal would let you write if statements which are an extension of the task statements above: when you would write {} = if … you can instead just write the if as a statement. (You'll get a type mismatch if any branches don't evaluate to a task whose output is {} though!) Same with when statements.


Last updated: Jun 16 2026 at 16:19 UTC