Introduction

The Monad language is a dependently typed, purely functional systems programming language that compiles through LLVM.

🌐 monad-lang.org

Warning

Monad is in alpha release and under heavy development. Many features are not implemented yet and are not tested properly. Expect breaking changes, incomplete functionality, and potential bugs.

Read the Maturity Matrix first — it says, area by area, what actually works today and what is still a sketch.

The Monad Logo

Hello World

Here is a simple example:

open IO {println}

def main (args : List String) : IO Unit := println "Hello, World!"

Save this as hello.mo and run it:

monad run hello.mo

run compiles the program and executes the result: a Monad program is always a native binary. (monad eval interprets one instead, but reaches only a handful of pure natives.) See Compiling and Running, which also covers where the monad binary itself comes from.

Key Features

Linear and affine types are a stated goal of the language, and the affine usage rule is enforced on every check and compile path: an unannotated binder may be used at most once unless its type is Copy. There is no annotation syntax — linearity comes from the type (#[linear], #[proof]), not from a binder prefix. See Linear Types.

Quick Example

open IO {println}

#[terminating]
def factorial (n : I64) : I64 :=
    if n == 0
    then 1
    else n * factorial (n - 1)

def main (args : List String) : IO Unit :=
    println (I64.to_string (factorial 5))

Two things in that example are worth noticing straight away, because they trip up everyone writing their first Monad program:

Where to go next