Core Library Overview
The core library provides the standard modules that Sector9 programs use for basic types, collections, system APIs, reusable proof patterns, and verified runtime helpers.
Import Paths
Core modules are imported with the mo:core prefix:
import Nat "mo:core/Nat";
import Text "mo:core/Text";
import Runtime "mo:core/Runtime";
import Token "mo:core/token/Fungible";
Subdirectories map to paths such as:
mo:core/pure/BMapmo:core/mutable/MBMapmo:core/ghost/Seqmo:core/axiom/Natmo:core/pattern/MapSummarymo:core/pattern/ICRCLedgermo:core/token/Fungiblemo:core/protocol/lib
Runtime vs Spec-Only
- Runtime modules are usable in normal code (for example,
Nat,Text,Runtime). - Spec-only modules are meant for contracts, ghost code, and proofs. These live under
mo:core/ghostandmo:core/axiom. - Pattern modules combine reusable ghost models and lemmas for common proof shapes, such as ledgers and map summaries. They are useful when a contract needs a stable model instead of re-deriving collection facts in every module.
Many runtime modules also provide a nested Spec module with trusted functions for specifications. Treat those functions like proof interfaces: they describe the model that verification uses, while runtime code continues to use the ordinary module API.
When running the examples directly from the repository, include the core package:
XDG_CACHE_HOME=/tmp/sector9 ./bin/sector9 --package core ./core/src --check docs/examples/08-core-library/nat-int.sr9
Module Map
Use these pages as entry points:
- Basic types and utilities: Types and Utilities
- Numeric types: Numeric Modules
- Text and binary data: Text, Blob, and Char
- Collections and iteration: Collections and Iteration
- B+tree map: Pure Map
- System APIs: Runtime and System
- Spec-only APIs and axioms: Ghost and Axiom Modules
- Proof patterns, tokens, and protocol schema: Patterns, Tokens, and Protocol Schema
- Per-module reference: Module Reference
Summary
- Import core modules with
mo:core/<Module>. - Spec-only APIs live under
mo:core/ghostandmo:core/axiom. - Higher-level helpers live under
mo:core/pattern,mo:core/token, andmo:core/protocol. - The pages below group modules by responsibility for fast lookup.