// Define a recursive enum for expressions
enum Expr { Num(Int); Mul(Expr, Expr) }
// Evaluate expression with pattern matching
fn eval(expr : Expr) -> Int {
match expr {
Num(n) => n
Mul(a, b) => eval(a) * eval(b)
}
}
fn main {
let expr = Mul(Mul(Num(2), Num(3)), Num(4))
println(eval(expr)) // 24
}
Why MoonBit?
Reliability
MoonBit catches mistakes early in both human and AI-generated code with a sound type system and predictable semantics. Its two-layer verification uses executable specifications and AI analysis to detect errors before production.
➜ server git:(main) ✗ moon check
Warning: [0056]
╭─[ /source/server/main.mbt:77:7 ]
│
77 │ let { name, email } = user
│ ───────┬───────
│ ╰───────── Warning (missing_pattern_field):
│ The struct pattern is missing the field(s) kind.
│ Please add them to the pattern or use `..` to ignore them.
────╯
Readable by Design
MoonBit keeps programs simple and predictable by avoiding complex ownership-based memory models. With strong pattern matching, data-oriented design, and semantic CLI tools, it helps developers and AI work with structured data and understand code more easily.
fn serve(path : String) -> Unit {
match path {
"/" | "/home" => render_home()
[.."/user/", ..id] =>
try @strconv.parse_int(id) catch {
error => render_not_found(error~)
} noraise {
number => render_user(number)
}
_ => render_not_found()
}
}
Toolchain for Agents
MoonBit provides an integrated platform with a compiler, build system, editor support, and AI-assisted tooling. Its unified toolchain makes it easy for developers and AI to build, test, and evolve software.
$ moon ide rename summary render_summary --loc content.mbt:10:8
# semantic rename that outputs a ready-to-apply patch
*** Begin Patch
*** Update File: /content_model/content.mbt
@@
content.views + content.title.length()
}
-pub fn summary(content : Content) -> String {
+pub fn render_summary(content : Content) -> String {
content.title + " - " + score(content).to_string()
}
*** End Patch
Fast Where It Matters
MoonBit bridges high-level productivity and low-level performance. Compared with TypeScript, ahead-of-time compilation eliminates JavaScript runtime overhead. Compared with Rust, programs remain easier to read and reason about while still delivering near-native performance.
Community Voices
The nice part about this is you can write nice functional code that iterates on collections (map, filter etc.) with hand-optimized-level performance. Every time I use map/filter in JS instead of plain for loops I feel like voluntarily giving up performance.
Beyond its compelling status as the top language for WASM development, the language is just a fun language to work with, hitting a sweet spot somewhere between Scala and Rust.
If anything, I'd rather use MoonBit than any of the mainstream options when presented with a choice... blazingly fast compile times and a nice package manager.
Network payload sizes matters on the Web. The MoonBit language is optimized to produce small Wasm payloads. Hello World is 27KB.
I'm finding MoonBit to be extremely easy to read... and its compiler is seriously fast... and the tooling is superb... I haven't had this much fun since I started liking Go!
MoonBit clearly lets you write things you couldn't in TypeScript, makes bloat-prone modules robust, ships a full toolchain built-in, lets you go native for speed, connect to the JS ecosystem, or push with wasm-gc builds. It's the best.
MoonBit 明らかにTSで書けなかったものが書けるし、モジュールの肥大化に耐えられなかった部分が堅牢になるし、必要なツールチェインが最初からビルトインだし、速度を取りに行って native 行ってもいいし、JSビルドで既存エコシステムと繋いでもいいし、wasm-gc ビルドで攻めてもいいし、最高だよ
MoonBit is a programming language designed specifically for generating WebAssembly binaries. Fast, incremental, and parallel compilation makes it suitable for large-scale development.
MoonBit is a new Wasm-first language. Optimized for tiny Wasm output, performance comparable to Rust, user-friendly with exhaustive pattern matching, managed memory, and CLI & IDE tooling.
MoonBit compiles 4,000 packages in under 7 seconds from a cold start and generates WebAssembly files as small as 253 bytes. Unlike Rust, it simplifies development through automatic memory management.
MoonBit combines the best parts of Rust, adds GC, and prioritizes tooling, performance, & stability.
As we approach the end of 2025, three programming languages are gaining serious momentum — Mojo, Rust, and MoonBit. Each brings something unique to the table: from systems-level speed to safe concurrency to WebAssembly-first
MoonBit is an end-to-end programming language that's optimized for WebAssembly, while also compiling to JavaScript and Assembly code.
We check out MoonBit, a modern language plus workflow designed to create efficient WebAssembly projects (it can also target JavaScript).
The nice part about this is you can write nice functional code that iterates on collections (map, filter etc.) with hand-optimized-level performance. Every time I use map/filter in JS instead of plain for loops I feel like voluntarily giving up performance.
Beyond its compelling status as the top language for WASM development, the language is just a fun language to work with, hitting a sweet spot somewhere between Scala and Rust.
If anything, I'd rather use MoonBit than any of the mainstream options when presented with a choice... blazingly fast compile times and a nice package manager.
Network payload sizes matters on the Web. The MoonBit language is optimized to produce small Wasm payloads. Hello World is 27KB.
I'm finding MoonBit to be extremely easy to read... and its compiler is seriously fast... and the tooling is superb... I haven't had this much fun since I started liking Go!
MoonBit clearly lets you write things you couldn't in TypeScript, makes bloat-prone modules robust, ships a full toolchain built-in, lets you go native for speed, connect to the JS ecosystem, or push with wasm-gc builds. It's the best.
MoonBit 明らかにTSで書けなかったものが書けるし、モジュールの肥大化に耐えられなかった部分が堅牢になるし、必要なツールチェインが最初からビルトインだし、速度を取りに行って native 行ってもいいし、JSビルドで既存エコシステムと繋いでもいいし、wasm-gc ビルドで攻めてもいいし、最高だよ
MoonBit is a programming language designed specifically for generating WebAssembly binaries. Fast, incremental, and parallel compilation makes it suitable for large-scale development.
MoonBit is a new Wasm-first language. Optimized for tiny Wasm output, performance comparable to Rust, user-friendly with exhaustive pattern matching, managed memory, and CLI & IDE tooling.
MoonBit compiles 4,000 packages in under 7 seconds from a cold start and generates WebAssembly files as small as 253 bytes. Unlike Rust, it simplifies development through automatic memory management.
MoonBit combines the best parts of Rust, adds GC, and prioritizes tooling, performance, & stability.
As we approach the end of 2025, three programming languages are gaining serious momentum — Mojo, Rust, and MoonBit. Each brings something unique to the table: from systems-level speed to safe concurrency to WebAssembly-first
MoonBit is an end-to-end programming language that's optimized for WebAssembly, while also compiling to JavaScript and Assembly code.
We check out MoonBit, a modern language plus workflow designed to create efficient WebAssembly projects (it can also target JavaScript).
The nice part about this is you can write nice functional code that iterates on collections (map, filter etc.) with hand-optimized-level performance. Every time I use map/filter in JS instead of plain for loops I feel like voluntarily giving up performance.
Beyond its compelling status as the top language for WASM development, the language is just a fun language to work with, hitting a sweet spot somewhere between Scala and Rust.
If anything, I'd rather use MoonBit than any of the mainstream options when presented with a choice... blazingly fast compile times and a nice package manager.
Network payload sizes matters on the Web. The MoonBit language is optimized to produce small Wasm payloads. Hello World is 27KB.
I'm finding MoonBit to be extremely easy to read... and its compiler is seriously fast... and the tooling is superb... I haven't had this much fun since I started liking Go!
MoonBit clearly lets you write things you couldn't in TypeScript, makes bloat-prone modules robust, ships a full toolchain built-in, lets you go native for speed, connect to the JS ecosystem, or push with wasm-gc builds. It's the best.
MoonBit 明らかにTSで書けなかったものが書けるし、モジュールの肥大化に耐えられなかった部分が堅牢になるし、必要なツールチェインが最初からビルトインだし、速度を取りに行って native 行ってもいいし、JSビルドで既存エコシステムと繋いでもいいし、wasm-gc ビルドで攻めてもいいし、最高だよ
MoonBit is a programming language designed specifically for generating WebAssembly binaries. Fast, incremental, and parallel compilation makes it suitable for large-scale development.
MoonBit is a new Wasm-first language. Optimized for tiny Wasm output, performance comparable to Rust, user-friendly with exhaustive pattern matching, managed memory, and CLI & IDE tooling.
MoonBit compiles 4,000 packages in under 7 seconds from a cold start and generates WebAssembly files as small as 253 bytes. Unlike Rust, it simplifies development through automatic memory management.
MoonBit combines the best parts of Rust, adds GC, and prioritizes tooling, performance, & stability.
As we approach the end of 2025, three programming languages are gaining serious momentum — Mojo, Rust, and MoonBit. Each brings something unique to the table: from systems-level speed to safe concurrency to WebAssembly-first
MoonBit is an end-to-end programming language that's optimized for WebAssembly, while also compiling to JavaScript and Assembly code.
We check out MoonBit, a modern language plus workflow designed to create efficient WebAssembly projects (it can also target JavaScript).
The nice part about this is you can write nice functional code that iterates on collections (map, filter etc.) with hand-optimized-level performance. Every time I use map/filter in JS instead of plain for loops I feel like voluntarily giving up performance.
Beyond its compelling status as the top language for WASM development, the language is just a fun language to work with, hitting a sweet spot somewhere between Scala and Rust.
If anything, I'd rather use MoonBit than any of the mainstream options when presented with a choice... blazingly fast compile times and a nice package manager.
Network payload sizes matters on the Web. The MoonBit language is optimized to produce small Wasm payloads. Hello World is 27KB.
I'm finding MoonBit to be extremely easy to read... and its compiler is seriously fast... and the tooling is superb... I haven't had this much fun since I started liking Go!
MoonBit clearly lets you write things you couldn't in TypeScript, makes bloat-prone modules robust, ships a full toolchain built-in, lets you go native for speed, connect to the JS ecosystem, or push with wasm-gc builds. It's the best.
MoonBit 明らかにTSで書けなかったものが書けるし、モジュールの肥大化に耐えられなかった部分が堅牢になるし、必要なツールチェインが最初からビルトインだし、速度を取りに行って native 行ってもいいし、JSビルドで既存エコシステムと繋いでもいいし、wasm-gc ビルドで攻めてもいいし、最高だよ
MoonBit is a programming language designed specifically for generating WebAssembly binaries. Fast, incremental, and parallel compilation makes it suitable for large-scale development.
MoonBit is a new Wasm-first language. Optimized for tiny Wasm output, performance comparable to Rust, user-friendly with exhaustive pattern matching, managed memory, and CLI & IDE tooling.
MoonBit compiles 4,000 packages in under 7 seconds from a cold start and generates WebAssembly files as small as 253 bytes. Unlike Rust, it simplifies development through automatic memory management.
MoonBit combines the best parts of Rust, adds GC, and prioritizes tooling, performance, & stability.
As we approach the end of 2025, three programming languages are gaining serious momentum — Mojo, Rust, and MoonBit. Each brings something unique to the table: from systems-level speed to safe concurrency to WebAssembly-first
MoonBit is an end-to-end programming language that's optimized for WebAssembly, while also compiling to JavaScript and Assembly code.
We check out MoonBit, a modern language plus workflow designed to create efficient WebAssembly projects (it can also target JavaScript).
Build with Brilliant Minds
MoonBit's open-source ecosystem is growing rapidly. Discover libraries, tools, and frameworks built by the community, or publish your own to mooncakes.io, the official MoonBit package registry.
The official MoonBit standard library.
moonbit-community/rabbitaTEA-based web framework for MoonBit.
moonbitlang/asyncAsynchronous programming library for MoonBit. Including fs, http, io, and more.