MoonBit (programming language)

MoonBit is a source-available, general-purpose programming language. 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.

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

Features

MoonBit follows the design principles of "fast, simple, and scale", includes the following features.

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.

Language design

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.

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.

Code example

The "Hello, World" program in MoonBit:

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

Ecosystem

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.

Usage

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

Seminar

On September 26, 2023, IoT Thrust Seminar | Moonbit For Cloud And Edge Using Wasm was held at Hong Kong University of Science and Technology.At the WASM I/O 2025 conference held on March 27-28, the talk MoonBit & WebAssembly: Unlocking the True Efficiency of Wasm was delivered by Hongbo Zhang.In LambdaConf 2025, a keynote session | Introduction to MoonBit and its Async Model is delivered.

The source code to the MoonBit compiler was made available under MoonBit Public Source License, a modified version SSPL, in December 2024.

Competition

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

See also

References

Uses material from the Wikipedia article MoonBit (programming language), released under the CC BY-SA 4.0 license.