Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

MoonBit

< >

MoonBit is a programming language created in 2022 by Hongbo Zhang.

#272on PLDB 2Years Old
Download source code:
git clone https://github.com/moonbitlang/core
Homepage · REPL · Source Code · Twitter · Docs

Intelligent developer platform for Cloud and Edge using WASM.


Example from the web:
fn main { println(@lib.hello()) }

Language features

Feature Supported Example Token
Interfaces trait Number { op_add(Self, Self) -> Self op_mul(Self, Self) -> Self }
Access Modifiers pub struct R2 { // 显式的公共结构 x: Int // 隐式的公共字段 pub y: Int // WARNING: `pub` 是多余的! priv z: Int // 显式的私有字段 }
Exceptions type! DivError String fn div(x: Int, y: Int) -> Int!DivError { if y == 0 { raise DivError("division by zero") } x / y }
Bitwise Operators 1 & 0
Pipes fn init { x |> f // 等价于 f(x) x |> f(y) // 等价于 f(x, y) }
Operator Overloading struct T { x:Int } derive(Show) fn op_add(self: T, other: T) -> T { { x: self.x + other.x } } fn main { let a = { x:0, } let b = { x:2, } println(a + b) }
Pattern Matching
Type Aliases pub typealias Index = Int typealias MapString[X] = Map[String, X]
Functions fn main { }
Enums enum Relation { Smaller Greater Equal }
Structs struct User { id: Int name: String mut email: String }
Maps let map : Map[String, Int] = { "x": 1, "y": 2, "z": 3 }
Hexadecimals 10
Octals 668
Floats 3.14
Integers 42
Booleans let a = true

- Build the next great programming language · Add · Issues · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements

Built with Scroll v164.7.0