A statically typed, purely functional, strictly evaluated programming language

that compiles to PHP, JVM and .NET. One .mog source — algebraic

data types, GADT's, pattern matching, type classes, explicit-effect IO — becomes a

.phar, a .jar or a .dll or native executable.

data Shape = Circle Double | Rect Double Double

deriving (Show, Eq)

area :: Shape -> Double

area s = case s of

Circle r -> 3.141592653589793 * r * r

Rect w h -> w * h

main :: IO ()

main = do

putStrLn (show (area (Circle 1.0)))

putStrLn (show (map area [Rect 2.0 3.0, Circle 1.0]))

3.141592653589793

[6.0,3.141592653589793]

Download the distribution for your platform from the releases page and unpack it — it is a complete installation, and running it needs nothing else:

tar -xzf moggi-0.1.0-linux-x86_64.tar.gz # or the .zip on Windows

cd moggi

./bin/moggi versionWrite a program:

-- hello.mog

main = putStrLn "Hello, world!"

./bin/moggi run hello.mog # compile and run it

./bin/moggi run examples/factorial # or run one of the shipped examples

./bin/moggi repl # try expressions interactivelyBuild an artifact you can deploy on its own:

./bin/moggi compile hello.mog # -> hello.phar

php hello.phar

./bin/moggi compile hello.mog --backend jvm # -> hello.jar

java -jar hello.jar

./bin/moggi compile hello.mog --backend dotnet # -> hello.dll

dotnet hello.dllWhich distributions bundle which runtime, and how to use a checkout instead:

Without -o the artifact is named after the entry source file; pass a full file

name to choose your own (-o app.phar, -o app.jar, -o app.dll).

Useful flags: --unpacked keeps the generated tree instead of packaging it,

--native builds a native executable (GraalVM native-image, .NET

PublishAot), and --tokens/--ast/--typed-ast/--ir/--opt-ir dump the

compiler's intermediate stages. --help lists everything.

Read them in order, or pick the question you have.

Full index: docs/README.md, which also lists the compiler's own documentation.

Moggi is alpha: the language and standard library are still being completed, and the three backends are kept byte-for-byte identical by a differential test.

Working on the compiler itself. Moggi the language needs none of this.

The flake pins every toolchain the compiler and test suite use — PHP 8.5, a JDK

21 (GraalVM, so native-image is there too), the .NET 8 SDK — and puts moggi

and runtest on your PATH:

nix developNix is for development, on Linux and macOS. On Windows, or without Nix, the same two commands work directly and use whatever toolchains you have installed:

php moggi.php version # the compiler (what the `moggi` wrapper runs)

php test.php # the test suite (what the `runtest` wrapper runs)php moggi.php --help documents the compiler's commands; php test.php --help

documents the suite's selection and reporting flags.

The editor extension is a separate project with its own release: moggi-lang/moggi-vscode-plugin.

runtest # the default backend (php)

runtest --backend jvm # another backend

runtest --backend all --native # every backend, plus native builds

runtest --group semantics # one group; a path below a group narrows further

runtest --list # what would runThe suite runs the compiler end to end: it compiles cases and compares generated code, IR, diagnostics and program output against goldens, on each backend they declare. docs/development/testing.md describes the layout, what a case looks like, and how goldens are updated.

Parts of this project — code, tests and documentation — were generated by large language models and reviewed by a human.