MoonBit
| 編程範型 | 多范型(函數式,指令式) |
|---|---|
| 設計者 | 張宏波 |
| 實作者 | MoonBit Team, 粵港澳大灣區數字經濟研究院 |
| 釋出時間 | 2023年 |
| 型態系統 | 靜態、強類型、類型推斷 |
| 作業系統 | 跨平台 |
| 許可證 | MoonBit Public Source License,可視為更寬鬆的 Server Side Public License |
| 文件擴展名 | .mbt |
| 網站 | www www |
| 受影響於 | |
| Rust、Go、OCaml | |
MoonBit 是由張宏波為主的團隊創始,現由粵港澳大灣區數字經濟研究院維護的一種專為高性能與資源效率設計的 通用型 程式語言 及 工具鏈,針對 WebAssembly 進行優化。[1][2]
MoonBit 的創建原因之一,在於其作者張宏波認為現有的語言如 Java、Go、Rust 等難以充分發揮 WebAssembly 指令集在 雲計算 和 邊緣計算 領域安全且快速的優勢。
除對 WebAssembly 的原生支持後,MoonBit 現已支持 JavaScript、Native,以及 LLVM 後端。[3]
MoonBit 於 2023 年 8 月 18 日公開發布,並於 2025 年 6 月 18 日進入 Beta 階段。
特性
[編輯]MoonBit 設計準則為「快速、簡單、可拓展」,支持 函數式、並行式、過程式 以及 面向對象 的程式設計風格。[4]
MoonBit 採用了 強類型 以及數據導向的語言設計,對 運行時、編譯時 性能,以及 Wasm 文件體積進行了優化,並提供了內置 調試、測試、值追蹤、AI 編程輔助、代碼覆蓋率工具測量等工具。[3]
設計理念
[編輯]MoonBit 的語法接近 Rust,是一種 強類型 語言,具有 模式匹配、靜態類型和類型推斷等語言特性,從而對 數據類型 實施嚴格限制。不同於 Rust 無垃圾回收的設計,MoonBit 引入了 垃圾回收器,並採用了 WasmGC 提案。[5][4]
在語言設計哲學上,作者張宏波表示,MoonBit 同樣從 Go 的「少即是多」中汲取了靈感,避免添加過多的語法。
MoonBit 設計為一門 大模型 友好的程式語言,採用實時基於語義的採樣器,並通過包括安全類型系統、Wasm 沙盒安全、死代碼消除的措施,確保 MoonBit 代碼生成的可靠性。[3]
代碼案例
[編輯]MoonBit 的 Hello World 程序如下:[3]
fn main {
println("hello world!")
}
生態
[編輯]MoonBit 的生態體系包含以下核心組件:
- Moon :MoonBit 程式語言的 構建系統。
- 外部函數接口(FFI)[7]:支持與宿主運行時集成,並可嵌入瀏覽器環境。
- 集成開發環境(IDE):在線 MoonBit IDE及 Visual Studio Code插件[8]。
應用
[編輯]2025 年 1 月,Golem Cloud 發布案例研究,介紹了 MoonBit 在 WebAssembly 組件構建中的應用[9]。
2025 年 3 月,北京大學在《程式語言設計原理》課程中採用 MoonBit 作為教學語言之一[10]。
2025 年 9 月,MoonBit 被收錄至 WebAssembly Component Model 官方文檔中[11]
會議
[編輯]2023 年 9 月,MoonBit 在香港科技大學(廣州)舉行的 IoT Thrust 研討會上發表題為 「MoonBit For Cloud And Edge Using Wasm」 的報告。[12]
2025 年 3 月,MoonBit 作者張宏波在 Wasm I/O 2025 發表演講《MoonBit & WebAssembly: Unlocking the True Efficiency of Wasm》。[13]
2025 年 5 月,MoonBit 作者張宏波在 LambdaConf 2025 發表主題演講(Keynote),介紹 MoonBit 的異步編程支持。 [14]
比賽
[編輯]2024 年 11 月,MoonBit 全球編程創新挑戰賽在河套深圳園區落下帷幕。[15]
參考
[編輯]- ^ Fei, Haoxiang; Zhang, Yu; Zhang, Hongbo; Wang, Yanlin; Liu, Qing. MoonBit: Explore the Design of an AI-Friendly Programming Language. Proceedings of the 1st International Workshop on Large Language Models for Code. LLM4Code '24 (New York, NY, USA: Association for Computing Machinery). 2024-09-10: 79–83. ISBN 979-8-4007-0579-3. doi:10.1145/3643795.3648376.
- ^ MoonBit Documentation. docs.moonbitlang.com. [2025-10-10].
- ^ 3.0 3.1 3.2 3.3 About us | MoonBit. www.moonbitlang.com. [2025-03-18] (中文(簡體)).
- ^ 4.0 4.1 MoonBit. www.moonbitlang.cn. [2025-03-15] (中文(簡體)).
- ^ moonbitlang/core, moonbitlang, 2025-03-15 [2025-03-15]
- ^ MoonBit 包管理平台. MoonBit. [2025-10-11] (中文).
- ^ Foreign Function Interface (FFI) — MoonBit v0.6.27 documentation. MoonBit Documentation. [2025-10-11] (英語).
- ^ Visual Studio Code 扩展. Visual Studio Marketplace. [2025-10-11] (英語).
- ^ Using MoonBit with Golem Cloud. Golem Cloud. 2025-01-03 [2025-10-10].
- ^ 编程语言设计原理课程. 北京大學. [2025-10-10].
- ^ Creating components. Bytecode Alliance. 2025-09-11 [2025-10-10].
- ^ IoT Thrust Seminar | Moonbit For Cloud And Edge Using Wasm. University Events. 2023-09-26 [2025-10-11] (中文(簡體)).
- ^ MOONBIT & WEBASSEMBLY: UNLOCKING THE TRUE EFFICIENCY OF WASM. Wasm I/O 2025. 2025-03-27 [2025-10-111].
- ^ Introduction to MoonBit and its Async Model. LambdaConf 2025. 2025-05-13 [2025-10-11].
- ^ 1888 进 11 角逐桂冠!MoonBit 全球编程创新挑战赛圆满落幕!_深圳新闻网. www.sznews.com. [2025-03-15].