Moggi documentation

The REPL

The REPL is the fastest way to try a piece of Moggi: type an expression, get its value; ask for a type; load a file and poke at it. Nothing is compiled to an artifact and nothing is left on disk.

moggi repl
Moggi REPL (php). Type :help for commands, :quit to exit.
> 1 + 2
3
> "Hello, " <> "world!"
Hello, world!
> map (\x -> x * 2) [1, 2, 3]
[2,4,6]
> add 1
<function>

What you can type

Commands

Every command starts with :. :help prints this list.

Command What it does
:type expr, :t the type of an expression or binding
:kind Type, :k the kind of a type (or of an expression’s type)
:info Name, :i declaration information for a name
:load file, :l load a module, so its definitions are in scope
:reload, :r reload the loaded module after editing it
:browse list the bindings defined in this session
:show imports show the active imports
:module [Name] show or set the interactive module name
:history command history
:clear reset the interactive state
:backend php\|jvm\|dotnet switch the evaluation backend
:quit, :q exit
> :type putStrLn
putStrLn :: String -> IO ()
> :kind Maybe
Maybe :: Type -> Type
> :load Demo/Shapes.mog
> area (Circle 2.0)
12.566370614359172

:backend is worth noticing once: the REPL evaluates on the backend you select, so :backend jvm is how you check that a program behaves the same off PHP — including the host calls in a foreign jvm declaration.

Looking inside the compiler

The same stages the compiler runs are available for a fragment, or for the whole interactive module:

Command Shows
:ast [expr\|decl] the parsed tree
:ir [expr\|decl] backend-neutral IR
:ir-opt [expr\|decl] IR after optimization
:emit [expr\|decl] the generated host code for the fragment
:emit-opt [expr\|decl] the same, optimized
:dump ast\|typed-ast\|ir\|ir-opt\|emit\|emit-opt that stage of the whole interactive module

For a file rather than a session, one flag each does the same and prints to stdout:

moggi compile hello.mog --tokens        # the token stream
moggi compile hello.mog --ast           # the parsed tree
moggi compile hello.mog --typed-ast     # after type checking and elaboration
moggi compile hello.mog --ir            # backend-neutral IR
moggi compile hello.mog --opt-ir        # after optimization

pipeline.md explains what each stage produces and where it lives, and optimizations.md documents the passes themselves.

Next

stdlib.md — find your way around the standard library.


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.