Pure functional programming with whole-program mutability inference
Rust
107
794 commits
updated Aug 22, 2026
This is the source code for the Morphic compiler.
Morphic is an experimental pure functional programming language designed to achieve performance competitive with imperative systems languages like C++ and Rust.
Morphic features three automatic optimizations which turn functional programming constructs into zero-cost abstractions:
type Primality {
Prime,
Composite,
}
sieve(limit: Int): Array Primality =
// Array memory is automatically managed statically,
// without any refcounting overhead in this case.
let init_arr =
Array.fill(limit, Prime)
|> Array.set(0, Composite)
|> Array.set(1, Composite)
in
// Iterator logic compiles to a simple loop, with
// no heap allocations or virtual dispatch.
Iter.range(2, limit)
|> Iter.foldl(init_arr, \(arr, n) ->
match Array.get(arr, n) {
Prime ->
Iter.ints(2)
|> Iter.map(\i -> i * n)
|> Iter.take_while(\i -> i < limit)
|> Iter.foldl(
arr,
// Array updates logically copy the array,
// but are automatically performed in-place
// when safe.
\(new, i) -> Array.set(new, i, Composite)
),
Composite -> arr,
}
)
To build Morphic you will need an up-to-date Rust compiler and a development copy of LLVM 16. Appropriate LLVM packages are available on Debian and Ubuntu from the LLVM repository. On other platforms, you may need to build LLVM from scratch. See the LLVM docs for details. Once you have installed Rust and LLVM 16, simply run cargo build.
Syntax highlighting is available via the Morphic VSCode Extension.
Typically, you should not need any extra environment variables when building Morphic. However, Morphic's build process does depend on the presence of several command line tools, and we provide the option to explicitly specify their locations via:
MORPHIC_CLANG_PATHRust
94.6%
C
1.9%
OCaml
1.5%
Python
1.4%
Pure functional programming with whole-program mutability inference
Rust
107
794 commits
updated Aug 22, 2026
This is the source code for the Morphic compiler.
Morphic is an experimental pure functional programming language designed to achieve performance competitive with imperative systems languages like C++ and Rust.
Morphic features three automatic optimizations which turn functional programming constructs into zero-cost abstractions:
type Primality {
Prime,
Composite,
}
sieve(limit: Int): Array Primality =
// Array memory is automatically managed statically,
// without any refcounting overhead in this case.
let init_arr =
Array.fill(limit, Prime)
|> Array.set(0, Composite)
|> Array.set(1, Composite)
in
// Iterator logic compiles to a simple loop, with
// no heap allocations or virtual dispatch.
Iter.range(2, limit)
|> Iter.foldl(init_arr, \(arr, n) ->
match Array.get(arr, n) {
Prime ->
Iter.ints(2)
|> Iter.map(\i -> i * n)
|> Iter.take_while(\i -> i < limit)
|> Iter.foldl(
arr,
// Array updates logically copy the array,
// but are automatically performed in-place
// when safe.
\(new, i) -> Array.set(new, i, Composite)
),
Composite -> arr,
}
)
To build Morphic you will need an up-to-date Rust compiler and a development copy of LLVM 16. Appropriate LLVM packages are available on Debian and Ubuntu from the LLVM repository. On other platforms, you may need to build LLVM from scratch. See the LLVM docs for details. Once you have installed Rust and LLVM 16, simply run cargo build.
Syntax highlighting is available via the Morphic VSCode Extension.
Typically, you should not need any extra environment variables when building Morphic. However, Morphic's build process does depend on the presence of several command line tools, and we provide the option to explicitly specify their locations via:
MORPHIC_CLANG_PATHRust
94.6%
C
1.9%
OCaml
1.5%
Python
1.4%