Skip to content

Modules & Imports

Almide organizes code into modules. The standard library provides modules for common operations, and user packages are imported the same way.

Import a module to use its functions:

import fs
import json
import regex
effect fn main() -> Result[Unit, String] = {
let content = fs.read_text("data.json")
let data = json.parse(content)
ok(())
}

All stdlib functions are called with a module prefix: fs.read_text(...), json.parse(...), string.trim(...).

FormSyntaxExample
Simpleimport moduleimport fs
Aliasimport module as nameimport mylib as m
Sub-moduleimport pkg.subimport mylib.parser
Selectiveimport pkg.{Name1, Name2}import mylib.{Parser, Lexer}
Self-aliasimport self as nameimport self as app

Wildcard imports (import fs.*) are a compile error.

These modules are available without import:

ModuleDescription
stringString manipulation
listList operations
mapMap operations
setSet operations
intInteger utilities
floatFloat utilities
mathMathematical functions
resultResult combinators
optionOption combinators
valueDynamic value operations

Auto-imported types and constructors:

  • Primitives: Int, Float, Bool, String, Unit, Path
  • Collections: List[T], Map[K, V], Set[T]
  • Error handling: Option[T], Result[T, E]
  • Constructors: some(x), none, ok(x), err(x)
  • Booleans: true, false
  • Boundary: Json, Value

These modules require an explicit import:

ModuleDescription
fsFile system operations (effect)
envEnvironment variables, timestamps (effect)
ioStandard I/O (effect)
processProcess execution (effect)
jsonJSON parsing and building
randomRandom number generation (effect)
regexRegular expressions
datetimeDate and time operations
httpHTTP client (effect)
logLogging (effect)
testingExtended test assertions
errorError utilities

These are implemented in Almide itself and imported the same way:

ModuleDescription
argsCommand-line argument parsing
pathFile path manipulation
optionOption[T] utilities
resultResult[T, E] utilities

Use as to create a shorter name for a module:

import mylib as m
m.hello()

Self-alias lets you reference the current package by name:

import self as app
app.some_function()

Import specific types or items from a module:

import mylib.{Parser, Lexer}

This brings Parser and Lexer directly into scope without a prefix.

Declarations default to public. Use mod or local to restrict access:

ModifierScope
(none)Public — accessible from anywhere
modSame project only
localSame file only
fn public_api() -> String = "anyone"
mod fn project_only() -> String = "same project"
local fn file_only() -> String = "same file"

Visibility applies to functions, types, and top-level let bindings:

local type InternalState = { data: String }
mod let INTERNAL_LIMIT = 100

Package identity is declared in almide.toml, not in source files. There is no module or package declaration at the top of .almd files.