MoonBit is a programming language created in 2022 by Hongbo Zhang.
#271on PLDB | 2Years Old |
git clone https://github.com/moonbitlang/core
Intelligent developer platform for Cloud and Edge using WASM.
fn main {
println(@lib.hello())
}
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 |