As of 6 Oct 2025, installation is via VSCode extension ("Moonbit Language") or manual (via curl
): curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
(macOS/Linux) or Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; irm https://cli.moonbitlang.com/install/powershell.ps1 | iex
(POSH)
///|
fn main {
// explicit type annotation
let a1 : Int = 10
println((10 : Int))
// Variable with type inference (Int inferred from value 20)
let b = 20
println("a + b = \{a1 + b}")
// Mutable variable - can be modified
let mut c = 10
println("c before: \{c}")
c = c + 1
println("c after: \{c}")
// Immutable variable - cannot be modified
let d = 20
println("d = \{d}")
// d = d + 1 // Uncommenting this line will cause a compilation error
}
let
bindings immutable; mut
bindings mutableInt
, Double
, Bool
, Char
(Unicode), String
(immutable), Unit
\u{...}
for Unicode\{variable}
fn
keyword->
for return type (Unit
assumed if not present)~
are labeled, and callers must use param name?
have default value, and callers must use param namereturn
or final expressionUnit
(()
) result[1, 2, 3]
Array::make
function; Array::make(4,1)
== [1, 1, 1, 1]
..arrayname
is "array spread"; expands the array's contents in-placearray[start:end]
obtains a view of the array from index start
to index end
(exclusive); referencetuple.0
, tuple.1
, etclet (a, b) = tuple
{"key1": value1, "key2" : value2}
Map::of
function; Map::of([("key1", 1), ("key2", 2), ("key3", 3)])
== {"key1":1, "key2":2, "key3":3}
map[key]
Last modified 11 October 2025