Try Monad in the Browser

https://monad-lang.org/try evaluates a Monad program entirely in your browser. The evaluator is the self-hosted compiler's own parser, scope builder, typechecker, lowerer and interpreter, compiled to WebAssembly and running in a Web Worker; the page is an Oak application.

It is experimental and unoptimised: the lowered program is interpreted directly, with no optimisation passes and no native code, so it runs far slower than a compiled binary. /try is a way to try the language, not a way to measure it.

The rule: define main

The scratchpad holds one complete module. The value of main is what the page shows, together with its type — the same convention as monad repl (eval::run, the shared evaluator, renders both):

def square (n : I64) : I64 := n * n

def main : I64 := square 12

The result pane shows 144 : I64.

main must take no parameters. A module with no main is a type error, not an empty result.

The prelude is not compiled into the evaluator. The page fetches the real init/src/*.mo files the site serves (sources.json lists them) and hands their text to the engine, so a program is checked against the same files the repository ships — every non-test init module is reachable with use init::…, not just the ones a hand-picked bundle carried.

The engine is motes/try_engine over eval::run — the same typecheck/elaborate/lower/evaluate recipe monad eval and monad repl use; only the loader (served sources instead of the filesystem) and the policy (fuel/depth, clipping) differ.

Because those sources are assembled in memory, the /try engine skips the compiler's module-load gates (manifest declarations and use completeness): a package-private init helper can resolve here that monad check would reject. Stick to the documented prelude API.

What is available

The ambient prelude only: the modules init re-exports (I64/String/ List/Option/Bool/Pair/Result, type classes and their instances, String and List helpers) plus prelude itself. You can define your own types, structs, classes, instances and infix operators.

type Shape {
    circle (r : I64),
    square (s : I64),
}

def area (s : Shape) : I64 :=
    match s {
        circle r => 3 * r * r,
        square x => x * x,
    }

def main : I64 := area (Shape.circle 2)

There is no filesystem, no network and no use of other motes. use init::… resolves; use std::… is rejected with a message.

The Examples row under the scratchpad loads a complete program in one click. They use ordinary operators (+ * / == |> ++) and the prelude's own helpers (List.map, Option.get_or_default, Foldable.foldl, String.to_lowercase), and cover records, recursion, ad-hoc types and a class instance.

What is not available (yet)

Limits and safety

Ctrl/Cmd+Enter

Runs the current program. The editor keeps your caret and undo history while you type; loading an example replaces the editor contents.

Running the page locally

devenv's docs-serve builds the two wasm modules and stages the served prelude sources before Zola starts. If you serve the site another way, run scripts/build-try.sh first and restart your server afterwards: docs/site/static/try/ holds a tracked page shell next to generated wasm/host files, sources.json and the sources/ tree, and a stale mix (a new worker.js with an old web_runtime.js, or an engine built before a module was added to init/src) makes every run fail to load.