Getting Started
This guide will take you from zero to running your first Mesh program. By the end, you will have Mesh installed, understand the basic project structure, and have compiled and run a working program.
What is Mesh?
Mesh is a statically-typed, compiled programming language designed for expressive, readable concurrency. It combines the actor model from Erlang/Elixir with a modern type system, pattern matching, and native compilation via Rust.
Key properties of Mesh:
- Statically typed with inference -- the compiler catches type errors at compile time, but you rarely need to write type annotations thanks to type inference
- Compiles to native code -- Mesh compiles through Rust to produce fast native binaries
- Actor-based concurrency -- lightweight actors with message passing, supervision trees, and fault tolerance built into the language
- Familiar syntax -- inspired by Elixir and Rust, with
do...endblocks, pattern matching, and pipe operators
Installation
Prerequisites
Mesh compiles through Rust, so you need the Rust toolchain installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shBuilding from Source
Clone the repository and build the compiler:
git clone https://github.com/snowdamiz/mesh-lang.git
cd mesh
cargo build --releaseVerifying Installation
After building, verify the compiler is available:
./target/release/mesh --versionYou should see the Mesh version number printed to the terminal.
Hello World
Create a file called hello.mpl:
fn main() do
println("Hello, World!")
endCompile and run it:
mesh hello.mplYou should see Hello, World! printed to the terminal.
Let's break down what's happening:
fn main()declares the entry point of the program -- every Mesh program starts heredo...enddefines the function bodyprintlnprints a string to stdout followed by a newline- Mesh source files use the
.mplfile extension
Your First Program
Now let's write something more interesting. Create a file called greet.mpl:
fn greet(name :: String) -> String do
"Hello, ${name}!"
end
fn main() do
let message = greet("Mesh")
println(message)
endRun it:
mesh greet.mplThis prints Hello, Mesh!. Here's what's new:
letcreates a variable binding -- variables in Mesh are immutable by default::provides a type annotation --name :: Stringmeans the parameternamehas typeString->declares the return type ---> Stringmeans the function returns aString"${name}"is string interpolation -- expressions inside${}are evaluated and inserted into the string- The last expression in a function is its return value -- no explicit
returnkeyword needed
Adding More Functions
Let's extend the program with some arithmetic:
fn add(a :: Int, b :: Int) -> Int do
a + b
end
fn double(x :: Int) -> Int do
x * 2
end
fn main() do
let sum = add(10, 20)
println("${sum}")
let result = double(7)
println("${result}")
let greeting = "Mesh"
println("Hello, ${greeting}!")
endThis demonstrates:
- Functions with multiple parameters
Inttype for integers- String interpolation with expressions:
"${sum}"converts the integer to a string automatically
Using the Pipe Operator
Mesh has a pipe operator |> that passes the result of one function as the first argument to the next:
fn double(x :: Int) -> Int do
x * 2
end
fn add_one(x :: Int) -> Int do
x + 1
end
fn main() do
let result = 5 |> double |> add_one
println("${result}")
endThis prints 11. The expression 5 |> double |> add_one is equivalent to add_one(double(5)) -- it reads left to right, making chains of transformations easy to follow.
What's Next?
Now that you have Mesh installed and running, explore the language in depth:
- Language Basics -- variables, types, functions, pattern matching, control flow, and more
- Type System -- structs, sum types, generics, and type inference
- Concurrency -- actors, message passing, supervision, and services