MoonCoc | 中文
A minimal Calculus of Constructions (CoC) core written in MoonBit. You can use it as a library in your own projects or run it as a standalone interactive application.
- Pure functional core: includes the
TermADT, substitution, reduction, and convertibility checking. - Type inference: a lightweight type checker with universe hierarchy support and clear error reporting.
- Dual usage modes:
- As a library: integrate into any MoonBit project via
moon add. - As a standalone app: clone the repo and run an interactive REPL.
- As a library: integrate into any MoonBit project via
Pick whichever way fits your workflow.
If you want to quickly try the CoC core or hack on it, clone this repository.
Steps:
-
Clone the repository
git clone https://github.com/Asterless/MoonCoc.git cd MoonCoc
-
Run the REPL
The repo ships with a simple REPL at
cmd/main.mbt. You can also script inputs viarepl_run_script:let outputs = @coc.repl_run_script([ "def id lam x sort 0 var x", "normalize app var id var y", ]) println("Outputs: " + outputs.join(", "))
Once you're ready, run
main.mbt:moon run cmd/main.mbt
To use MoonCoc's API in your MoonBit project, add it as a dependency.
Steps:
-
Add the dependency
moon add Asterless/MoonCocThen add this import in your
moon.pkg.json:{ "import": [ { "path": "Asterless/MoonCoc/src", "alias": "coc" } ] } -
Use it in code
You can call functions like
repl_initandrepl_processto drive the core.fn my_app() { // Initialize REPL state let state = @coc.repl_init() // Define a term let step1 = @coc.repl_process(state, "def id lam x sort 0 var x") println(step1.output) // => "Defined: id : Pi(x,Sort(0),Sort(0))" // Infer its type let step2 = @coc.repl_process(step1.state, "infer var id") println(step2.output) // => "Pi(x,Sort(0),Sort(0))" }
src/
term.mbt # Term data type and ops (Eq, Show, constructors)
errors.mbt # Custom error types
utils.mbt # Utilities (e.g., universe level helpers)
typing.mbt # Typing context and type inference core
repl.mbt # REPL implementation
test.mbt # Tests
cmd/
main.mbt # Entry point for the interactive REPL
Contributions are welcome. A few guidelines:
- After changes, run
moon info && moon fmtto update interfaces and format code. - Before committing, run
moon testto ensure all tests pass. Usemoon test --updateif your intentional changes affect snapshots. - Found a bug or have an idea? Open an issue.
Licensed under Apache-2.0.