Skip to content

Modules

File-based module system with qualified names.


Qosm has a file-based module system. Each .qosm file is automatically a module — no imports needed.

Module naming

Module names are derived from filenames using PascalCase:

| File | Module Name | |------|-------------| | helpers.qosm | Helpers | | math_utils.qosm | MathUtils | | http_client.qosm | HttpClient |

Using modules

Reference functions from other modules with Module.function:

// In helpers.qosm
let format_name name = "Mr. " ++ name;

// In main.qosm — no import needed
let greet name = "Hello, " ++ Helpers.format_name name;

Constructors must also be qualified:

// In types.qosm
type Color = | Red | Green | Blue;

// In main.qosm
let c = Types.Red;
match c with (
| Types.Red -> "red"
| Types.Green -> "green"
| Types.Blue -> "blue")

Creating modules in the workspace

In the workspace editor:

  1. Click the + button in the file tabs
  2. Enter a filename (e.g., helpers.qosm)
  3. Write your helper functions
  4. Reference them from main.qosm using qualified names

Best practices

  • Put entry-point functions (what users will call) in main.qosm
  • Put helpers and utilities in separate modules
  • Use descriptive module names (Formatters, Validators, ApiHelpers)
  • Within your own file, all names are bare — no self-qualification needed

Capabilities in modules

All modules share the same capability environment. If http_get is enabled, any module can call it:

// api_helpers.qosm — uses http_get capability directly
let fetch_json url =
  match http_get {url: url, headers: []} with (
  | Ok{value: body} -> parse_json @{data: String} body
  | Err{value: e} -> Err{value: e});

// main.qosm
let result = ApiHelpers.fetch_json "https://api.example.com/data";