Jump to content

MoonBit (programming language)

From Wikipedia, the free encyclopedia
MoonBit
ParadigmsFunctional, imperative
Designed byZhang Hongbo
DeveloperMoonBit Team
First appeared2023; 2 years ago (2023)
Typing discipline
Memory managementGarbage collected (WasmGC)
Implementation languageOCaml
PlatformWasm
OSCross-platform
LicenseServer Side Public License
Filename extensions.mbt
Websitewww.moonbitlang.com
Influenced by
Rust, Go, OCaml

MoonBit is a general-purpose programming language.[1][2] It is developed by a team led by Zhang Hongbo. One of the motivations behind MoonBit's creation was Zhang's belief that existing languages like Java, Go, and Rust do not fully leverage the security and speed advantages of the WebAssembly instruction set, particularly in cloud computing and edge computing. After its initial release with native WebAssembly support, MoonBit later added support for JavaScript, Native, and the LLVM backend.[3]

MoonBit was publicly released in August 2023 and is currently in its pre-beta stage.[3]

Features

[edit]

MoonBit follows the design principles of "fast, simple, and scale" and supports functional programming, parallel computing, procedural programming, and object-oriented programming styles.[4]

The language is strongly typed and data-oriented, with optimizations for runtime and compile-time performance as well as Wasm file size. It provides built-in tools for debugging, software testing, value tracing, AI-assisted programming, and code coverage analysis.[3]

Language design

[edit]

MoonBit has a syntax similar to Rust and is a strongly typed language featuring pattern matching, static types, and type inference to enforce strict data type constraints. Unlike Rust, which does not use garbage collection, MoonBit includes a garbage collector and adopts the WasmGC proposal.[5][4]

According to its creator Zhang Hongbo, MoonBit draws inspiration from Go's philosophy of simplicity, avoiding unnecessary complexity in syntax.

MoonBit is designed to be a LLM-friendly programming language, using real-time semantic sampling. It ensures reliability in code generation through a secure type system, Wasm sandboxing, and dead code elimination.[3]

Code example

[edit]

The "Hello, World" program in MoonBit:[3]

fn main {
    println("hello world!")
}

Ecosystem

[edit]

At launch, MoonBit provided a web-based IDE along with a Visual Studio Code extension. The language's IDE and compiler share a unified codebase, allowing MoonBit to be a first-class language in Visual Studio Code due to its fault-tolerant type system.

  • Moon is MoonBit's build system.
  • mooncakes.io is MoonBit's package management system, used for building, managing, and maintaining third-party packages.
  • Foreign function interface (FFI) is used for interoperability when embedding MoonBit in a browser or interacting with a host runtime.

MoonBit employs a multi-backend approach, optimizing for different targets, including WebAssembly, JavaScript, Native, and LLVM.[3]

Usage

[edit]

MoonBit has a Visual Studio Code extension that provides out-of-the-box debugging, code completion, and tooltips.[3]

Seminar

[edit]

On September 26, 2023, IoT Thrust Seminar | Moonbit For Cloud And Edge Using Wasm was held at Hong Kong University of Science and Technology.[6]

MoonBit compiler was open-sourced under MoonBit public license, a permissive SSPL, in December 2024.[7]

Competition

[edit]

In November 2024, the MoonBit Global Programming Innovation Challenge Concludes at Hetao Shenzhen Park.[8]

See also

[edit]

References

[edit]
  1. ^ Fei, Haoxiang; Zhang, Yu; Zhang, Hongbo; Wang, Yanlin; Liu, Qing (2024-09-10). "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: 79–83. doi:10.1145/3643795.3648376. ISBN 979-8-4007-0579-3.
  2. ^ "MoonBit Documentation — MoonBit v0.1.20250310 documentation". docs.moonbitlang.com. Retrieved 2025-03-15.
  3. ^ a b c d e f g "About us | MoonBit". www.moonbitlang.com. Retrieved 2025-03-18.
  4. ^ a b "MoonBit". www.moonbitlang.com. Retrieved 2025-03-15.
  5. ^ moonbitlang/core, moonbitlang, 2025-03-15, retrieved 2025-03-15
  6. ^ "IoT Thrust Seminar | Moonbit For Cloud And Edge Using Wasm". University Events (in Simplified Chinese). 2023-09-26. Retrieved 2025-03-15.
  7. ^ "MoonBit compiler is available on GitHub | MoonBit". www.moonbitlang.com. 2024-12-18. Retrieved 2025-04-04.
  8. ^ "1888进11角逐桂冠!MoonBit全球编程创新挑战赛圆满落幕!_深圳新闻网". www.sznews.com. Retrieved 2025-03-15.
[edit]