Moggi documentation

Standard library

The standard library is written in Moggi and lives in lib/. It is part of the compiler: every program is compiled against it automatically, so you never compile the library yourself — you just import from it. In an installation that is the lib/ directory next to bin/, shipped as ordinary sources: read them whenever a signature is not obvious, they are covered by the same LICENSE. It is one package, base — lib/base.moggi is its descriptor, and a release publishes it at registry.moggi-lang.org/#/pkg/base.

import Data.Map as M
import System.Filesystem (removeFile)

Module names follow the names you would expect from the language Moggi borrows its shape from (Data.List, Data.Maybe, Data.Map, System.IO, Control.Monad, …), and so do the names each module exports. Two namespaces are worth knowing about:

The Prelude (implicitly imported everywhere) carries the basic types, classes and functions — see tour.md for what is in it and what needs an explicit import.

What is in it today

Grouped by namespace, these are the modules a program can import. The list is the honest one: a name appears here because lib/ has it, and the API of each is Haskell base’s API (porting rules and the few deliberate differences are in differences-to-haskell.md).

Namespace Modules
Prelude implicitly imported everywhere; the re-export list
Control.* Applicative, Monad, Monad.Fail, Exception (+ Exception.Base)
Data.* Bits, Bifunctor, Bool, Bounded, ByteString (+ Char8), Char, Either, Enum, Eq, Foldable, Function, Functor, Int, List (+ NonEmpty), Map, Maybe, Monoid, Ord, Proxy, Semigroup, Set, String, Traversable, Tuple, Void, Word
Data.Time.* Clock
Numeric.* Natural
System.* Environment, Exit, Filesystem (+ Filesystem.Path), IO (+ IO.Base, IO.Error, IO.Types)
Text.* Show, Read
Moggi.* the compiler-facing side: Internal.* (the primitives, the numeric types, Show/Read machinery), Exception, Err, Generics, IO.Exception

Not there yet, and listed so nobody hunts for them: Data.Ratio, Data.Complex, Data.Fixed, Data.Functor.Identity, Data.Functor.Const, and Control.Monad.Reader/State/ST. Classes that exist only in part (RealFrac, Floating, RealFloat, most Read instances, CallStack) are listed in §7 of differences-to-haskell.md, which is the one place that tracks what is still missing.

Finding your way around it

You do not have to know a module name in advance. Two tools read the same index, built from the -- | doc comments in the sources:

moggi moogle fromMaybe                # search by name
moggi moogle -- "a -> a"              # search by type (`--` so `-` is not a flag)
moggi moogle --json "Maybe a"         # machine-readable, for your own tooling

moggi mogdoc lib -o out/doc           # static HTML for every module
moggi mogdoc serve --port 8080        # local preview while you read

Open out/doc/index.html and the pages are browsable: each module lists its declarations with signatures and doc comments, a facade module’s page links to its backend implementations, and the internal modules are indexed too. moogle is the terminal version of the same search, and it answers the question you type — “what is it called”, “what has this type”, “where is Foldable”.

Searching by type is the one worth remembering, because it is how you find the function you want without knowing its name:

moggi moogle -- "Maybe a -> a"        # -> fromMaybe
moggi moogle -- "[a] -> Int"          # -> length

Both commands take --lib for extra library roots and --root to search a directory of your own code instead of the standard library.

Building it on its own

moggi compile lib -o out/lib      # a library build: nothing is stripped

An executable build (moggi compile app) keeps only what main reaches. A library build keeps everything, which is what you want when the compiled library is an output in its own right: --lib-php out/lib then lets a later single-file compile reuse that precompiled tree.


Moggi compiles to PHP, the JVM and .NET. This site is generated from docs/ in the moggi-lang/moggi repository; the same pages are readable there as Markdown.