hn.today

ConcurrentML: Improving on Go's Concurrency Model

nikhilism.com7 points0 comments
Screenshot of ConcurrentML: Improving on Go's Concurrency Model

Concurrent ML (CML) rethinks Go’s CSP-style concurrency by turning communication operations into first-class values called events. Instead of immediately performing a send or receive, code builds descriptive event values and later executes them with a sync operation. That separation lets the language expose composable primitives for choice and cancellation: event combinators like handle-evt attach post-commit actions to an event, choice-evt composes alternatives, and alarm-evt/timeout-evt provide timeouts. Because events encapsulate both setup and post-commit behavior, callers and libraries can compose synchronization policies (e.g., combining timeouts, competing requests, or quit signals) without leaking implementation details. Racket provides a modern, maintained implementation of CML and is used for the examples.

Concrete examples illustrate the payoff: a Fibonacci producer shows sync with handle-evt and a make-quit-evt to encapsulate quitting; a fetch-from-fastest-url example uses choice-evt plus timeout-evt to race HTTP requests and enforce a deadline without context.Context. The central claim is that these patterns are effectively impossible in Go because channel operations aren’t values and start executing immediately (spawning goroutines that return channels is not equivalent). CML also simplifies cancellation and can eliminate goroutine-leak footguns through garbage-collected event semantics, enabling libraries to spawn threads internally while leaving composition and shutdown to callers.

Read on nikhilism.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

My C23 Conventions

My C23 Conventions

Abner Coimbre discusses modern C conventions in C23, emphasizing the use of maybe_unused to handle unused return values and improve code clarity. He also highlights issues with designated initializers not zero-initializing structs, leading to more careful struct initialization practices. (abner.page)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.