Imports and modules¶
This page explains the mental model behind Incan modules and imports.
For details and tasks, use the split pages:
- How-to: Imports and modules (how-to)
- Reference: Imports and modules (reference)
Key ideas¶
- Incan supports two import styles (Python-style and Rust-style) that can be mixed freely.
- Modules are discovered from the filesystem — there is no explicit
moddeclaration step. - Directories can act as modules; use
mod.incnas the “main file” for a directory module when needed. - Common types and functions are available without imports via the prelude (see the reference page for the full list).
Coming from Python?
In Python, packages are driven by directory structure and __init__.py.
In Incan, directories are recognized automatically; you can use mod.incn when you need a directory/module
entrypoint.
How module discovery works (conceptual)¶
When you import a local module, the compiler:
- Resolves the path (handling
.,..,super,crate) - Finds the
.incnfile (ormod.incnfor directories) - Parses and type-checks that file
- Makes its types and functions available in the importing file
Coming from Rust¶
In Rust, you typically need explicit module declarations before importing. In Incan, you generally “just import” and the compiler discovers modules automatically.
Coming from Python¶
In Python, packages are driven by directory structure and __init__.py. In Incan, directories are recognized as modules
without __init__.py; use mod.incn when you need a directory entrypoint.
Where to go next¶
- Practical multi-file project layouts: Imports and modules (how-to)
- Full import syntax, path rules, prelude contents: Imports and modules (reference)