moggi-lang/moggi

Moggi Compiler

PHP

2

7 commits

updated Sep 24, 2026

See the code

See what people are saying

README

Moggi

Moggi

.github/workflows/test.yml

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]

Quick start

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 version

Write 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 interactively

Build 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.dll
BackendArtifactToolchain
php (default)hello.pharPHP 8.5+
jvmhello.jarJDK 21+
dotnethello.dll (+ hello.deps.json, hello.runtimeconfig.json).NET 8 SDK

Which distributions bundle which runtime, and how to use a checkout instead:

DistributionBundles
moggiPHP, .NET SDK, JDK, GraalVM — everything, including --native
moggi-phpPHP
moggi-dotnetPHP and the .NET SDK
moggi-jvmPHP, JDK and GraalVM
moggi-minimalnothing — uses the runtimes on your PATH

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.

Documentation

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

TopicGuide
Getting running (start here)docs/quickstart.md
The language, by exampledocs/tour.md
Try expressions, inspect typesdocs/repl.md
Find your way around lib/docs/stdlib.md
Complete syntaxdocs/language.md
Calling PHP, the JVM or .NETdocs/ffi.md
Derivingdocs/deriving.md
Errors, exceptions, stack tracesdocs/diagnostics.md
How the compiler works, stage by stagedocs/pipeline.md
Differences from Haskell, whose names the library follows (not needed to use Moggi)docs/differences-to-haskell.md
Language server (LSP)docs/lsp.md
VS Code extensionmoggi-lang/moggi-vscode-plugin
Environment variablesdocs/env-vars.md

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.

Development

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

Environment

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 develop

Nix 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.

Repository layout

PathPurpose
moggi.phpCLI entry point (Moggi\CLI\main)
src/The compiler, written in PHP
lib/The Moggi standard library, written in Moggi
tests/Compiler test suite
examples/Small programs to run and read
dist/, launcher/, scripts/dist/The release distributions and the native launcher
schnorr/Schnorr signature CLI (BIP-340), built alongside the launcher

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

Tests

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 run

The 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.

More

TopicGuide
Dev shell, debugging, editor setupdocs/development/development.md
Test suite: layout, writing cases, goldensdocs/development/testing.md
Compiler architecturedocs/development/architecture.md
Compiler stages, module by moduledocs/development/compiler.md
Design decisions and invariantsdocs/development/design.md
Optimizer passesdocs/development/optimizations.md
Building the distributionsdist/README.md

AI disclaimer

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

Contributors

prolic

6 commits

moggi-lang/moggi

Moggi Compiler

PHP

2

7 commits

updated Sep 24, 2026

See the code

See what people are saying

README

Moggi

Moggi

.github/workflows/test.yml

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]

Quick start

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 version

Write 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 interactively

Build 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.dll
BackendArtifactToolchain
php (default)hello.pharPHP 8.5+
jvmhello.jarJDK 21+
dotnethello.dll (+ hello.deps.json, hello.runtimeconfig.json).NET 8 SDK

Which distributions bundle which runtime, and how to use a checkout instead:

DistributionBundles
moggiPHP, .NET SDK, JDK, GraalVM — everything, including --native
moggi-phpPHP
moggi-dotnetPHP and the .NET SDK
moggi-jvmPHP, JDK and GraalVM
moggi-minimalnothing — uses the runtimes on your PATH

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.

Documentation

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

TopicGuide
Getting running (start here)docs/quickstart.md
The language, by exampledocs/tour.md
Try expressions, inspect typesdocs/repl.md
Find your way around lib/docs/stdlib.md
Complete syntaxdocs/language.md
Calling PHP, the JVM or .NETdocs/ffi.md
Derivingdocs/deriving.md
Errors, exceptions, stack tracesdocs/diagnostics.md
How the compiler works, stage by stagedocs/pipeline.md
Differences from Haskell, whose names the library follows (not needed to use Moggi)docs/differences-to-haskell.md
Language server (LSP)docs/lsp.md
VS Code extensionmoggi-lang/moggi-vscode-plugin
Environment variablesdocs/env-vars.md

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.

Development

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

Environment

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 develop

Nix 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.

Repository layout

PathPurpose
moggi.phpCLI entry point (Moggi\CLI\main)
src/The compiler, written in PHP
lib/The Moggi standard library, written in Moggi
tests/Compiler test suite
examples/Small programs to run and read
dist/, launcher/, scripts/dist/The release distributions and the native launcher
schnorr/Schnorr signature CLI (BIP-340), built alongside the launcher

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

Tests

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 run

The 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.

More

TopicGuide
Dev shell, debugging, editor setupdocs/development/development.md
Test suite: layout, writing cases, goldensdocs/development/testing.md
Compiler architecturedocs/development/architecture.md
Compiler stages, module by moduledocs/development/compiler.md
Design decisions and invariantsdocs/development/design.md
Optimizer passesdocs/development/optimizations.md
Building the distributionsdist/README.md

AI disclaimer

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

Contributors

prolic

6 commits

Languages

PHP

98.3%