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.

Your own files are modules too. The sample below has two of them — switch tabs inside the playground to see greeting.almd, and note that the file name is the module name:

Almide
main.almdgreeting.almd
import self.greeting

fn main() -> Unit = {
  println(greeting.polite("Ada"))
  println(greeting.casual("Ada"))
}
Press Run to compile and execute this in your browser

Locally the same code is a project: src/main.almd plus src/greeting.almd.

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
errorError construction and chaining
datetimeDate and time operations
bytesBinary data
matrixMatrix operations
int8uint64, float32Sized numeric types

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: 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
httpHTTP client (effect)
testingExtended test assertions

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

ModuleDescription
argsCommand-line argument parsing
pathFile path manipulation
base64Base64 encoding
hexHexadecimal encoding

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 loads the package entry point src/mod.almd, so that file must exist; a sibling file is reached with import self.<name> and needs no entry point:

import self as app // requires src/mod.almd
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.