Roc version 0.1.0, eight years in the making

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Roc version 0.1.0, eight years in the making

After eight years of development, the Roc programming language has its first numbered release: version 0.1.0!

经过八年的开发,Roc 编程语言迎来了它的第一个版本号发布:0.1.0 版本!

There are too many contributors to thank for all their incredible work on the road to this milestone, but I at least want to mention (in alphabetical order) Agus Zubiaga, Anthony Bullard, Anton-4, Aurélien Geron, Ayaz Hafiz, Brendan Hansknecht, Brian Carroll, Folkert de Vries, Hannes, Jack Scully, Jared Ramirez, Jasper Woudenberg, Jelle Teeuwissen, Josh Warner, JRI98, Luke Boswell, MagicMan, Niclas Åhdén, Sam Mohr, Stephan, and Steve Howell.

在通往这一里程碑的道路上,有太多的贡献者需要感谢,感谢他们所做的不可思议的工作。但我至少想(按字母顺序)提一下:Agus Zubiaga、Anthony Bullard、Anton-4、Aurélien Geron、Ayaz Hafiz、Brendan Hansknecht、Brian Carroll、Folkert de Vries、Hannes、Jack Scully、Jared Ramirez、Jasper Woudenberg、Jelle Teeuwissen、Josh Warner、JRI98、Luke Boswell、MagicMan、Niclas Åhdén、Sam Mohr、Stephan 和 Steve Howell。

Thank you all so much!

非常感谢大家!

Roc is a programming language with the tagline fast, friendly, functional.

Roc 是一门以“快速、友好、函数式”为口号的编程语言。

It’s designed to build faster than Go and output programs that run nearly as fast as Rust, with user-friendly tooling and a friendly community, plus security and reliability guarantees you can’t find in any mainstream language today. Roc hasn’t achieved all of its goals yet (version 0.1 is not 1.0!) but as you’ll see, 0.1.0 has a lot.

它的设计目标是比 Go 构建速度更快,输出运行速度接近 Rust 的程序,同时具备用户友好的工具链和友好的社区,以及在当今任何主流语言中都无法找到的安全性和可靠性保证。Roc 尚未实现其所有目标(0.1 版本不是 1.0 版本!),但正如你所见,0.1.0 版本已经包含了很多内容。

Roc 0.1.0 compiles to standalone binaries (with hot reloading out-the-box) or to WebAssembly, it combines Hindley-Milner type inference with purity inference and static dispatch, and uses a novel system of platforms and applications to let you build on lower-level languages without a FFI compromising guarantees.

Roc 0.1.0 可以编译为独立二进制文件(开箱即用支持热重载)或 WebAssembly。它结合了 Hindley-Milner 类型推断、纯度推断和静态分发,并使用了一种新颖的平台与应用程序系统,让你能够在底层语言的基础上进行构建,而无需通过 FFI(外部函数接口)来妥协安全性保证。

I started designing the language in 2018 with a goal of making an Elm-inspired experience for “the long tail of use cases.” Back then, Elm was focused only on user interfaces, although now with Acadia its scope has expanded—check it out if you haven’t already! Roc has evolved its own character over time, so although the languages still have much in common, there are some obvious differences too.

我于 2018 年开始设计这门语言,目标是为“长尾用例”创造一种受 Elm 启发的体验。那时,Elm 只专注于用户界面,尽管现在随着 Acadia 的出现,其范围已经扩大——如果你还没看过,不妨去了解一下!随着时间的推移,Roc 已经发展出了自己的特色,因此尽管这两种语言仍有许多共同点,但也存在一些明显的差异。

I made the first compiler commit in 2019, and talked about the project publicly in 2020. More contributors got involved then, leading to promising early results that I spoke about at Strange Loop 2021. We incorporated research from the Koka and Morphic languages, but hit a major architectural problem along the way, which I talked about in detail with Ayaz Hafiz in 2024. This led to a 2025 scratch-rewrite of the compiler, which we completed earlier in 2026.

我在 2019 年提交了第一个编译器代码,并于 2020 年公开谈论了这个项目。随后更多的贡献者参与进来,带来了我在 Strange Loop 2021 大会上提到的早期成果。我们整合了来自 Koka 和 Morphic 语言的研究成果,但在过程中遇到了一个重大的架构问题,我曾在 2024 年与 Ayaz Hafiz 详细讨论过。这导致了 2025 年对编译器的彻底重写,我们在 2026 年初完成了这项工作。

Many details in the language’s design changed over those years, yet the types in the standard library still look about how they did in my 2018 sketches. (One of the reasons for holding off on making a numbered release was to set a clear expectation not to expect stability. Things are much more stable these days!)

多年来,语言设计的许多细节发生了变化,但标准库中的类型看起来仍然与我 2018 年草图中的样子差不多。(推迟发布版本号的原因之一,是为了明确传达“不要期望稳定性”的预期。如今情况已经稳定多了!)

There’s more detail about language specifics below, as well as a showcase of projects community members have built. But first, some numbers!

下面有关于语言细节的更多信息,以及社区成员构建的项目展示。但首先,让我们看一些数据!

One of Roc’s goals is to approach the performance of speed-focused languages like Rust and C++, without quite matching it (since Roc does automatic memory management and is stricter about memory safety than Rust, and both of those design choices have runtime performance costs). So how close can Roc get?

Roc 的目标之一是接近 Rust 和 C++ 等注重速度的语言的性能,虽然不完全匹配(因为 Roc 采用自动内存管理,并且在内存安全性方面比 Rust 更严格,而这两种设计选择都会带来运行时性能成本)。那么,Roc 能达到多接近呢?

Here are some performance benchmarks across four community projects. Each includes a comparison to Rust or C, and all were built with the highest levels of optimization in their respective compilers.

以下是四个社区项目的性能基准测试。每个测试都包含了与 Rust 或 C 的对比,并且所有项目都使用了各自编译器中的最高优化级别进行构建。

In How close can pure FP get to C?, I compared Niclas Åhdén’s roc-deflate with C’s libdeflate across 144 compression benchmarks. You can read more about these measurements in that article, but the quick summary is that roc-deflate had a median slowdown (compared to libdeflate) of 2.6% on an M1 MacBook Pro and 8.9% on a Ryzen 3900X. Here’s the main chart from that article:

在《纯函数式编程能有多接近 C?》(How close can pure FP get to C?)一文中,我对比了 Niclas Åhdén 的 roc-deflate 与 C 语言的 libdeflate 在 144 个压缩基准测试中的表现。你可以在那篇文章中阅读更多关于这些测量的数据,但简要总结是:在 M1 MacBook Pro 上,roc-deflate 的中位减速(与 libdeflate 相比)为 2.6%,在 Ryzen 3900X 上为 8.9%。以下是该文章中的主要图表: