ocaml2moonbit-migration
Installation
SKILL.md
OCaml to MoonBit Migration
Port behavior, data invariants, and public contracts first. Translate syntax only after the source semantics are classified. The most common porting bug is silently coercing OCaml string (a byte sequence) into MoonBit String (UTF-16 text); classify every field by meaning before choosing a type.
When in doubt, probe with moon run -c '...'. Probes in this guide were verified on moon 0.1.20260512-class toolchains; rerun the relevant probe if the local toolchain is newer and the behavior is load-bearing.
Migration Workflow
- Inventory the OCaml module boundary: public types, functions, exceptions, optional arguments, mutable state, lazy/deferred state, C/Unix/filesystem dependencies, and existing tests or golden fixtures.
- Classify every OCaml
stringby meaning before choosing a MoonBit type. Do this field by field, even inside the same OCaml record. - Choose MoonBit package boundaries and imports before coding. Add imports to
moon.pkg; MoonBit source files do not use OCaml-styleopen. - Port one behavioral slice at a time with tests. Prefer a thin public API skeleton, then fill parser/serializer/algorithm internals behind it.
- Probe uncertain language or library behavior with
moon run -cand, when needed, a small OCaml toplevel probe. Keep probes minimal. - Finish each slice with
moon check,moon test,moon info, andmoon fmt. You can add more warningsmoon check --warn-list +...to be more strict.