Skip to content
Playground

Modules

use

yulang
use std::undet::*
use std::list::map
use std::ops::{(+), (-)}
use my_module::old_name as new_name
use noisy::* without debug

use brings names from a module into scope. * imports everything visible. Imports may be grouped with {...}, renamed with as, and filtered with without. Operator names can be imported with parentheses, such as (+).

Companion modules

Every struct, type ... with:, enum, act, error, and role declaration creates a companion module of the same name. our and pub bindings inside the body live there:

yulang
struct point { x: int, y: int } with:
    our p.norm2 = p.x * p.x + p.y * p.y

point::norm2 (point { x: 3, y: 4 })
// or equivalently:
point { x: 3, y: 4 } .norm2

For enum and error, the variants are members of the companion (opt::just 1, fs_err::not_found "p"). Prelude reexports make common variants such as just, nil, ok, and err available without qualification. For act, the operations are members (console::println_native "hi" in std::console).

Dot selection

expr.method first selects fields or methods associated with the receiver's type, then can resolve role methods and effect-row methods. This works for:

  • Structs: field accessors and methods declared in with:
  • type ... with: methods, such as methods on standard-library list or str
  • Role methods, such as .add, .index, or .show
  • Effect-row methods, such as nondeterminism collectors .list, .logic, and .once

Selection on a record (anonymous, structural) instead pulls the field by name. Act operations themselves are normally reached by path, for example console::println_native "hi".

Standard library modules

ModuleHighlights
std::preludeEntry files normally import this: Add, Eq, Ord, Display, len, id, compose, last/next/redo, return, fail, range operators, and core std reexports
std::opsOperator definitions: +, -, *, /, ==, !=, <, <=, >, >=, and, or, not
std::listList operations: map, filter, fold, sort, cons, uncons, rev, append, …
std::rangeRange constructors and Fold impl
std::optopt 'a, with prelude-reexported nil and just
std::resultresult 'ok 'err, with prelude-reexported ok and err, plus map, and_then, unwrap_or
std::strstr type, Index impls
std::varref 'e 'a and update helpers
std::flowsub, loop, label-loop primitives
std::foldFold role with .fold plus default .find and .contains methods
std::undeteach, guard, list, once, logic
std::junctionall, any for effectful comparisons
std::consolesay, println, print, plus host-handled print_native / println_native
std::fsread_text, read_at, open, write_text, exists, is_file, is_dir, plus fs_err errors
std::errorThrow role
std::indexIndex role

Yulang