Skip to content

Add if! (if-bang) keyword to computation expressions #863

@jwosty

Description

@jwosty

Add if! (if-bang) keyword to computation expressions

I propose we extend computation expressions with a new keyword, if! (if-bang), that functions a let! (let-bang) combined with an if statement. For example, instead of writing:

let! shouldSolveWorldHunger = confirmAsync ("Solve world hunger?")
if shouldSolveWorldHunger then solveWorldHunger () else dont ()

or even:

match! confirmAsync("Solve world hunger?") with
| true -> solveWorldHunger ()
| false -> dont ()

We should be able to do:

if! confirmAsync("Solve world hunger?") then
    solveWorldHunger ()
else dont ()

Pros and Cons

Pros: Aids code readability in specialized cases.

Cons: It's work, and it increases complexity. (whether or not this is worth the effort for potentially such small return is up to debate / whoever would do it, but I figure it's worth filing [probably low priority :) ] since I am not aware of a prior suggestion -- would be brownie points for the F# language)

Extra information

S

Related suggestions: (put links to related suggestions here)

#572

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions