A missed opportunity masquerading as a killer feature.

This article is part of a series called Worse is better, in which I muse on technologies and techniques that became popular despite superior alternatives. Think VHS versus Betamax.

In this article, I will argue that the celebrated async/await language feature pioneered by C# should rather be classified as a missed opportunity. F# did async first, and better, but of course Haskell does monads even better.

Since the introduction in C# the async and await keywords have been ported to multiple other languages, including C++, Python, JavaScript, and more. With such apparent success, it seems odd to complain that it's worse than alternatives.

My Richard-Gabriel moment #

To be honest, async/await is perfectly cromulent. Pragmatically it solves real problems. What's the complaint?

As examples go, this is perhaps the most direct counterpart to Gabriel's original lament about C++ and Lisp. Gabriel considered Lisp superior to C++ because Lisp was a coherent and elegant system. Still, the heterogeneous hacked-together nature of C++ enabled faster time to market, eventually outcompeting Lisp.

Adding async and await keywords to a language is comparable to the C++ approach. Instead of solving a general problem, it only solves a particular problem, albeit a large one.

Computation expressions #

What makes this so regrettable is that a general language-design solution already existed. As witnessed by language version history, F# already had asynchronous workflows with syntactic sugar in 2007. This language feature still exists today:

member _.GetRecommendationsAsync userName = task { // <- async
    // v await
    let! scrobbles = songService.GetTopScrobblesAsync userName

    // The rest of the code block follows...

This example is from Porting song recommendations to F#, although I've clipped the code and changed the comments for didactic reasons.

The language feature is called computation expressions, and while the base library comes with a few built-in computation expressions, it's a completely user-definable feature. My article Song recommendations with F# free monads has a comprehensive example, but usually, a few lines of code are enough.

The original 2007 computation expression was called async, and it's still around. Since it predated the .NET Task Parallel Library, it was based on its own implementation of Async<'T>.

Later, the F# core library also got task expressions to support the de-facto standard of using Task<T> for asynchronous processing. No new language feature was required.

In the above code example, task introduces the computation expression, roughly corresponding to the C# async keyword. Likewise, the exclamation point ! in let! corresponds to await. The beauty of the F# language design is that while it perfectly supports asynchronous programming, it's by no means specialized to that task.

Short-circuiting workflows #

Computation expressions can add syntactic sugar for any functor, applicative functor, or monad, although you get the most bang for your buck with the latter.

For example, you can write short-circuiting workflows if you add a little computation expression builder for the option type. For instance, you could rewrite Cpr.tryParse from the article Danish CPR numbers in F# to something like this:

// string -> CprNumber option
let tryParse (candidate : string ) =
    let canonicalized = candidate.Trim().Replace("-", "")
 
    option {
        let! dayString               = canonicalized |> String.trySubstring 0 2
        let! dayCandidate            = dayString |> Int.tryParse
 
        let! monthString             = canonicalized |> String.trySubstring 2 2
        let! monthCandidate          = monthString |> Int.tryParse
 
        let! yearString              = canonicalized |> String.trySubstring 4 2
        let! yearCandidate           = yearString |> Int.tryParse
 
        let! sequenceNumberString    = canonicalized |> String.trySubstring 6 4
        let! sequenceNumberCandidate = sequenceNumberString |> Int.tryParse
 
        return! tryCreate
            dayCandidate
            monthCandidate
            yearCandidate
            sequenceNumberCandidate
    }

This workflow may fail at every step marked by an exclamation point. If it does, it stops processing the rest and simply returns None.

This behaviour didn't require a new keyword, or any new language feature, but instead relies on the general-purpose computation-expression language feature and, in this case, a little user-defined expression builder:

type OptionBuilder () =
    member _.Bind (x, f) =
        match x with
        | Some v -> f v
        | None -> None
    member _.Return x = Some x
    member _.ReturnFrom x = x
 
[<AutoOpen>]
module OptionBuilder =
    let option = OptionBuilder ()

While this is already quite elegant, it still requires a bit of (reusable) boilerplate for every functor you wish to support, such as option, result, task, etc.

Programmable semicolons #

Haskell, with its more powerful type system, fully automates this process. Every Monad (or Applicative with the ApplicativeDo extension) instance enables you to drop into do notation, which gives you nice syntactic sugar for the monad in question.

Since Maybe is a Monad instance, you don't have to write any user-code equivalent to the above OptionBuilder. Just drop into do notation, and the compiler automatically handles the workflow for you. As an example, you could port the above tryParse function to Haskell like this:

tryParse :: String -> Maybe CPRNumber
tryParse candidate =
  let canonicalized = filter (/= '-') $ trim candidate
  in do
    let (dayStr, rest1) = splitAt 2 canonicalized
    let (monthStr, rest2) = splitAt 2 rest1
    let (yearStr, rest3) = splitAt 2 rest2
    let sequenceNumberStr = take 4 rest3
    day <- readMaybe dayStr
    month <- readMaybe monthStr
    year <- readMaybe yearStr
    sequenceNumber <- readMaybe sequenceNumberStr
    tryCPRNumber day month year sequenceNumber

All the variables bound by <- arrows may cause the computation to short-circuit. This syntax is equivalent to F# let! bindings. Returning a short-circuiting value is also possible in both cases, but while F# requires the return! keyword, in Haskell this is done by omitting return.

This Haskell language features is so powerful that Real World Haskell (among other sources) calls it 'programmable semicolon'. You could use the same phrase for F# computation expressions.

Where C# falls short #

The async/await feature of C# provides syntactic sugar similar to F# computation expressions and Haskell do notation, but unfortunately, only for asynchronous workflows. As long as your 'outer' monad is Task<T> it works decently, but it doesn't address other cases, like the above examples of short-circuiting computation.

Ironically, C# has another language feature that enables syntactic sugar for monadic workflows: Query syntax (AKA LINQ). You can see a small example in the Maybe monad article, as well as plenty of other articles on this site. You could port the above CPR example to C# and achieve short-circuiting behaviour using query syntax.

Is it possible to use query syntax with asynchronous workflows too? Yes, indeed, since asynchronous computations are also monadic. Is the async/await language feature redundant, then?

No, because query syntax has other limitations.

Venn diagram of computation expressions showing overlap between LINQ and async/await. Both support sequential composition; LINQ uniquely emphasizes extensibility, while async/await uniquely includes branching and commands. Parallel composition is shown as part of computation expressions in general, but is not a member of neither LINQ nor async/await.

As this diagram attempts to capture, while LINQ works for any monad (any functor, in fact), it supports neither branching nor Commands. That is, you can't use if or switch inside of a LINQ query, and you can't call void methods. You can see an example of the kind of trouble the latter issue causes in my Preserved in translation video. Another example of the awkwardness of LINQ can be seen in the article Flattening arrow code using a stack of monads.

On the other hand, as already covered, async/await does support branching and Commands, but is not user-definable; it only works for asynchronous workflows.

Finally, while both support sequential composition (monadic bind), none of them support 'parallel' composition, which is what you can get by ignoring monads and instead emphasising applicative functors. By 'parallel' I mean that you can compose independent computations in a way where what happens to one computation does not short-circuit the rest of the composition. This is particularly useful for validation, as shown in An F# demo of validation with partial data round trip. More specifically, it can be used to implement true parallelism, as demonstrated by the Haskell async package.

Language design versus implementation #

To be clear, my gripe about async/await is about programming-language design. Given the language design choice, the C# (or rather: .NET) implementation of async/await is impressive. Clearly, a lot of work has gone into making it work efficiently.

People who know how async/await and the Task Parallel Library works may consider the async package primitive at best, and possibly cheating. As far as I can tell, the Haskell async package creates a new thread every time you enter an Async computation. This can be expensive, and may not be necessary.

A C# Task, on the other hand, may or may not run on a separate thread. Often they utilize thread pools and relinquish threads back to a pool while waiting for external I/O events. A lot of thought has gone into the implementation, and my experience is that it works well. The Haskell async package does none of that, as far as I can tell.

The F# task computation expression, however, is simply syntactic sugar over the .NET implementation, thereby demonstrating that you can get the best of both worlds. A sophisticated, efficient implementation controlled by elegant and extensible language design.

Conclusion #

C#'s async/await language feature is so celebrated that other languages have adopted it. Even languages with little or no connection to Microsoft, such as Python and JavaScript, have a similar feature, sometimes even using the same keywords. Surely, this is a sign of success?

The async/await language feature is, in my eyes, a perfect example of Gabriel's maxim that worse is better. It's an essentially ad-hoc addition by way of adding more keywords to an already-complicated programming language.

What makes this disappointing is that a more elegant language design was already known at the time. C# could have got its own version of F# computation expressions, which would have enabled both language designers and 'normal' programmers to solve many more problems using the same, universal tool.

Of course, since C# already has two competing, partially overlapping kinds of syntactic sugar, I can't rule out that one day, it'll get a third, proper language feature that solves this once and for all. But I don't really believe that. That ship has sailed.

Which only underscores the message from the previous article: F# is a better programming language than C#.



Wish to comment?

You can add a comment to this post by sending me a pull request. Alternatively, you can discuss this post on Twitter or somewhere else with a permalink. Ping me with the link, and I may respond.
Published: Monday, 16 November 2026 07:36:00 UTC